Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using FormsAuthentication in my website. When a user requests a page while they are not authenticated, they are redirected to the login page. Once the use is authenticated, the user is redirected to the requested page. I would like the application to ALWAYS redirect to the default page, not the requested page. Is this too much to ask?

Here's my web.config:

XML
<authentication mode="Forms">
    <forms loginUrl="~/Account/Login.aspx" timeout="2880" defaultUrl="Default.aspx" />
</authentication>



Here's my authentication code from the login page:

FormsAuthentication.RedirectFromLoginPage(employeeID, true);


What am I missing?? Thanks!
Posted

1 solution

Are you using the Login control? If so, handle the LoggedIn event and redirect as necessary
 
Share this answer
 
Comments
jasonHall 23-Dec-10 12:48pm    
No, this is a custom Login page. I'm using my own authentication method by calling a stored procedure, not FormsAuthentication.Authenticate(). Perhaps I shouldn't use the RedirectFromLoginPage method and use Response.Redirect(), but then I don't understand how the rest of the application will know that the session is authenticated.
[no name] 23-Dec-10 14:11pm    
RedirectFromLoginPage: Redirects an authenticated user back to the originally requested URL...

In your case then yes you would need to use Response.Redirect
jasonHall 23-Dec-10 14:35pm    
If I use:
Response.Redirect("Default.aspx");
instead of:
FormsAuthentication.RedirectFromLoginPage(employeeID, true);

I'm just transfered back to the Login page. Obviously I am not redirecting correctly. Anyone have any input on how this can be done?
[no name] 23-Dec-10 14:54pm    
Since where implementing your own login method I though you knew to call SetAuthCookie to set the authentication token
jasonHall 23-Dec-10 15:45pm    
Well, I do now! :) So far, so good! For those of you wondering what that would look like, here is the code that I've used in the login form:
FormsAuthentication.SetAuthCookie(employeeID, false);
Response.Redirect("~/Default.aspx");

Thanks Mark!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900