【问题标题】:How to use form authentication without aspnetdb?如何在没有 aspnetdb 的情况下使用表单身份验证?
【发布时间】:2013-03-07 11:51:24
【问题描述】:

我正在开发一个小型网站,它将成为大型网站的一部分。它没有自己的身份验证和数据库,但我想对它使用表单身份验证。我在 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 

【问题讨论】:

    标签: asp.net aspnetdb form-authentication


    【解决方案1】:

    我不确定我的代码有多好,但它现在确实可以工作......

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-30
      • 2012-04-23
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      相关资源
      最近更新 更多