首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ASP.NET - AuthenticateRequest()中缺少ticket.UserData(),新服务器上安装了旧的工作代码

ASP.NET - AuthenticateRequest()中缺少ticket.UserData(),新服务器上安装了旧的工作代码
EN

Stack Overflow用户
提问于 2013-02-22 23:23:05
回答 1查看 224关注 0票数 0

我刚刚将一个旧的(ASP.NET 2.0)网站迁移到一个新的服务器上。该应用程序已经维护了大约8年(升级到ASP.NET 4),并且在旧服务器上运行良好。它在我的开发计算机上也运行得很好。

我这周大部分时间都在寻找答案,尝试了几个选项,但我仍然无法找到这个答案。任何帮助/指针都将不胜感激。

下面是最相关的运行代码片段。

蒂娅,雷蒙德

代码语言:javascript
运行
复制
Shared Function LogMeIn(ByVal p As Page, ByVal sUserName As String, ByVal sPassword As     String, ByVal bPersists As Boolean, ByVal lblMessage As Label) As Integer
    Try
        'get the login dataset
        Dim dsLogin As DataSet = GetUserDataSetByUserName(sUserName)

        If dsLogin.Tables(0).Rows.Count = 1 Then

            FormsAuthentication.Initialize()

            Dim sGoodPassword As String = dsLogin.Tables(0).Rows(0).Item("Password").ToString
            Dim sRole As String = dsLogin.Tables(0).Rows(0).Item("Roles").ToString

            'check password
            If sPassword = sGoodPassword Then
                Dim ticket As New FormsAuthenticationTicket(1, _
                                                            sUserName, _
                                                            DateTime.Now, _
                                                            DateTime.Now.AddMinutes(60 * 480), _
                                                            bPersists, sRole, _
                                                               FormsAuthentication.FormsCookiePath)

                Dim hash As String = FormsAuthentication.Encrypt(ticket)
                Dim cookie As New HttpCookie(FormsAuthentication.FormsCookieName, hash)

                If ticket.IsPersistent Then cookie.Expires = DateTime.Now.AddDays(15)

                cookie.HttpOnly = True

                p.Response.Cookies.Add(cookie)

                Dim sReturnUrl As String = "..." 'removed for clarity

                p.Response.Redirect(sReturnUrl, True)

            Else
                lblMessage.Text = "Incorrect Password"
                Return 1
            End If
        Else
            '... 'removed for clarity
        End If
    Catch ex As Exception
        '... 'removed for clarity
    End Try

End Function


Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)

    ' Fires upon attempting to authenticate the use
    If Not (HttpContext.Current.User Is Nothing) Then

        Dim gpUser As GenericPrincipal = HttpContext.Current.User


        If gpUser.Identity.IsAuthenticated Then
            If TypeOf gpUser.Identity Is FormsIdentity Then

                Dim fi As FormsIdentity = CType(gpUser.Identity, FormsIdentity)

                Dim ticket As FormsAuthenticationTicket = fi.Ticket
                Dim sRoles As String()
                Dim i As Integer

                sRoles = ticket.UserData.Split(",")
                For i = 0 To sRoles.Length - 1
                    sRoles(i) = Trim(sRoles(i))
                Next

                HttpContext.Current.User = New GenericPrincipal(fi, sRoles)

            End If
        End If
    End If

End Sub
EN

Stack Overflow用户

回答已采纳

发布于 2013-03-28 08:20:18

这个问题与以下事实有关:我使用的是Access数据库,而该站点最初是在ASP.NET 1.0上构建的。解决方案是实现自定义成员资格和角色提供程序。

http://www.codeproject.com/Articles/27955/Developing-custom-ASP-NET-Membership-and-Role-prov

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15027422

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档