我刚刚将一个旧的(ASP.NET 2.0)网站迁移到一个新的服务器上。该应用程序已经维护了大约8年(升级到ASP.NET 4),并且在旧服务器上运行良好。它在我的开发计算机上也运行得很好。
我这周大部分时间都在寻找答案,尝试了几个选项,但我仍然无法找到这个答案。任何帮助/指针都将不胜感激。
下面是最相关的运行代码片段。
蒂娅,雷蒙德
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发布于 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
https://stackoverflow.com/questions/15027422
复制相似问题