没有aspnetdb如何使用表单身份验证?

时间:2013-03-07 11:51:24

标签: asp.net aspnetdb form-authentication

我正在开发一个小网站,它将成为大型网站的一部分。它不会有自己的身份验证和数据库,但我想使用它进行表单身份验证。我在web.config中添加了几行

<authentication mode="Forms">
  <forms loginUrl="Login.aspx" timeout="2880" defaultUrl="Default.aspx" />
</authentication>
<authorization>
    <deny users="?"/>
</authorization>

在代码中,我需要具备什么?????????地点?目前,它只会停留在登录页面,不会重定向到默认页面。顺便说一下,登录页面实际上不是一个登录页面,它只是一个将从大型网站调用的页面,并检查用户是否被授权。

If everything is fine Then


                ?????????????????
                FormsAuthentication.SetAuthCookie("UserName", True)
                FormsAuthentication.RedirectFromLoginPage("UserName", True)

 Else
         'show error

 End If 

1 个答案:

答案 0 :(得分:0)

我不确定我的代码有多好,但现在确实有用......

Protected Sub DoLogin()

    Dim authCookie As HttpCookie = FormsAuthentication.GetAuthCookie(UserName, False)
    Dim ticket As FormsAuthenticationTicket = FormsAuthentication.Decrypt(authCookie.Value)
    Dim newTicket As New FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, "")
    authCookie.Value = FormsAuthentication.Encrypt(newTicket)
    Response.Cookies.Add(authCookie)
    Response.Redirect("Default.aspx", False)

End Sub