Forms Authentication - login to different page depending upon credentials

matthisco

New member
Joined
Nov 18, 2009
Messages
2
Programming Experience
Beginner
I've tried to use this code:

VB.NET:
if(username.Text = "admin" and password.Text = "xxx")

response.redirect("upload.aspx")


elseif (username.Text = "neds" and password.Text = "xxx")

response.redirect("neds.aspx")


end if

However, nothing happens, the page stays the same and the url changes to:

login.aspx?ReturnUrl=%2fupload.aspx

Can anyone please tell me how I can direct people to different pages depending upon the username they enter?

Thankyou
 
You will have to create a Forms Authentication Ticket and add it to the Response object before you can redirect the user. If you do not do this, the request is not authenticated and it redirects user back to the login page.

The code for creating a ticket that needs to be added before you do a redirect will look like

Dim objTicket As FormsAuthenticationTicket = Nothing
Dim objCookie As HttpCookie = Nothing
Dim strReturnURL As String = Nothing
objTicket = New FormsAuthenticationTicket(1, Username.Text, System.DateTime.Now, DateTime.Now.AddMinutes(60), False, Session.SessionID)
objCookie = New HttpCookie(".ASPXAUTH")
objCookie.Value = FormsAuthentication.Encrypt(objTicket)
Response.Cookies.Add(objCookie)

Let me know if you still have issues.
 
Back
Top