0

古い(ASP.NET 2.0)Webサイトを新しいサーバーに移行しました。アプリケーションは約8年間維持され(ASP.NET 4にアップグレード)、古いサーバーで正常に動作していました。開発用コンピューターでも正常に動作しています。

私は今週のほとんどの期間、答えを探していて、いくつかのオプションを試しましたが、それでもこれを理解することはできません。ヘルプ/ポインタをいただければ幸いです。

以下は、実行中のコードの最も適切なスニペットです。

TIA、レイモンド

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
4

1 に答える 1

0

この問題は、Accessデータベースを使用していて、サイトが元々ASP.NET1.0で構築されていたという事実に関連していました。解決策は、カスタムのメンバーシップおよびロールプロバイダーを実装することでした。

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

于 2013-03-28T00:20:17.910 に答える