User Login
-
I haven't done much ASP.Net so I hope this is a small problem: I have a page where the users can log in to the website. Their role depends on what page they get redirected to, so I am handeling the LoggedIn event of the Login control:
protected void Login_LoggedIn(object sender, EventArgs e) { if (User.IsInRole("Admin") == true) { Server.Transfer("Admin/Default.aspx"); } else if (User.IsInRole("SuperAdmin") == true) { Server.Transfer("SuperAdmin/Default.aspx"); } else { Server.Transfer("User/Default.aspx"); } }
I have no idea if this is the best way to do someting like this... But my problem is that when, let's say the Admin, loggs in they will get the user page(supposed to be admin's) the first time and it says that they have not been authenticated. However, if i hit back and login again it says that they have been authenticated and it goes to the right page. Anyone have any ideas why this is hapening? Thanks in advance ;P -- modified at 13:33 Sunday 23rd April, 2006
-
I haven't done much ASP.Net so I hope this is a small problem: I have a page where the users can log in to the website. Their role depends on what page they get redirected to, so I am handeling the LoggedIn event of the Login control:
protected void Login_LoggedIn(object sender, EventArgs e) { if (User.IsInRole("Admin") == true) { Server.Transfer("Admin/Default.aspx"); } else if (User.IsInRole("SuperAdmin") == true) { Server.Transfer("SuperAdmin/Default.aspx"); } else { Server.Transfer("User/Default.aspx"); } }
I have no idea if this is the best way to do someting like this... But my problem is that when, let's say the Admin, loggs in they will get the user page(supposed to be admin's) the first time and it says that they have not been authenticated. However, if i hit back and login again it says that they have been authenticated and it goes to the right page. Anyone have any ideas why this is hapening? Thanks in advance ;P -- modified at 13:33 Sunday 23rd April, 2006
+ You should use the
Response.Redirect
method instead of theTransfer
method to redirect the user to the default page. + Another option that you can try in the handler of theLoggedIn
event handler is that after you determine the default web page based on the user role, you then simply assign the web page to theDestinationPageUrl
property of the Login control, and have the control do the rest. -
I haven't done much ASP.Net so I hope this is a small problem: I have a page where the users can log in to the website. Their role depends on what page they get redirected to, so I am handeling the LoggedIn event of the Login control:
protected void Login_LoggedIn(object sender, EventArgs e) { if (User.IsInRole("Admin") == true) { Server.Transfer("Admin/Default.aspx"); } else if (User.IsInRole("SuperAdmin") == true) { Server.Transfer("SuperAdmin/Default.aspx"); } else { Server.Transfer("User/Default.aspx"); } }
I have no idea if this is the best way to do someting like this... But my problem is that when, let's say the Admin, loggs in they will get the user page(supposed to be admin's) the first time and it says that they have not been authenticated. However, if i hit back and login again it says that they have been authenticated and it goes to the right page. Anyone have any ideas why this is hapening? Thanks in advance ;P -- modified at 13:33 Sunday 23rd April, 2006
please check with the ispostback is true or false with regards, susa
-
+ You should use the
Response.Redirect
method instead of theTransfer
method to redirect the user to the default page. + Another option that you can try in the handler of theLoggedIn
event handler is that after you determine the default web page based on the user role, you then simply assign the web page to theDestinationPageUrl
property of the Login control, and have the control do the rest.I dont think you are understanding my question. The user is not getting directed to the right page because they are not being authenticated when they hit login. I put: Response.Write(User.IsAuthenticated.ToString()); on the page that the user kept getting directed to after they logged in and it says false. So for some reason, its not authenticating the user the first time they login. Which is weird because I have made it so that you need to be logged in before you can access the user page and yet it is letting them go there. So its a bit odd :confused: Furthermore, when I switch Server.Transfer to Response.Redirect it keeps sending the user back to the login page!!? Any ideas?
-
I dont think you are understanding my question. The user is not getting directed to the right page because they are not being authenticated when they hit login. I put: Response.Write(User.IsAuthenticated.ToString()); on the page that the user kept getting directed to after they logged in and it says false. So for some reason, its not authenticating the user the first time they login. Which is weird because I have made it so that you need to be logged in before you can access the user page and yet it is letting them go there. So its a bit odd :confused: Furthermore, when I switch Server.Transfer to Response.Redirect it keeps sending the user back to the login page!!? Any ideas?
Sean89 wrote:
I dont think you are understanding my question.
I'm sorry.
Sean89 wrote:
Any ideas?
IMO, there are a couple of reasons as to why the application sends the user back to the login page: + The username/password is not correct (might not be this case). + The user account is not authorised to view the web page in the Admin or SuperAdmin folder. So could you double check the authorization settings of your application, especially for the Admin/SuperAdmin folder. + The authentication ticket is not added. Have you tried to debug your application and step through your sample code line by line and see what is actually happening?