Question

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 
Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top