简体   繁体   中英

How to use form authentication without aspnetdb?

I am developing a small website which will be part of a big website. It won't have its own authentication and database but I want to use form authentication with it. I put in few lines in web.config

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

In the code, what do I need to have in that ???????? place? At the moment, it will just stay at the login page and doesn't not redirect to Default page. Btw, Login page is not really a login page it's just a page that will be called from the big website and check if the user is authorized or not.

If everything is fine Then


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

 Else
         'show error

 End If 

I am not sure how good my code is but it does work for now ...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM