C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Forms Authentication - Redirecting users to a Page other than Default.aspx


Posted Date: 13 Sep 2006    Resource Type: Articles    Category: Web Applications
Author: Harish RanganathanMember Level: Gold    
Rating: Points: 10



Introduction


In this article I will explain how to redirect users to a specific page rather than the generic default.aspx upon successful authentication of the user.

Forms based authentication


While using ASP.NET Forms authentication, if we try to access a protected page, the user would be taken to the login.aspx page with the ReturnUrl parameter having the path for the originally requested page.

Once, the user's credentials are verified, the RedirectFromLoginPage method can be used to take the user back to the originally requested page.

However, if there is no specified ReturnUrl, then FormsAuthentication by default takes the user to the default.aspx page upon successful authentication.

What if we dont have a Default.aspx Page?


If we do not have a default.aspx page or we want to take the users to our custom page etc., then we can use the Setauthcookie method to set the cookie and then redirect users to our desired page. The following code establishes the same.


// Once the user's entered credentials are verified //
if(Request.Params["ReturnUrl"] != null)
{
FormsAuthentication.RedirectFromLoginPage(txtUserName.text, false);
}
else
{
FormsAuthentication.SetAuthcookie(txtUserName.text, false);
Response.Redirect("CustomPage.aspx");
}


The above code first verifies whether there is any ReturnUrl parameter such that if exists, it should take to the originally requested page.

Else, it sets the authcookie and then redirects user to a custom page.

The txtUserName is the ID of the textbox which is used to capture the username.

Applies to


This article applies to ASP.NET 1.0 & 1.1 Versions.

Summary


This article discussed on how we can redirect users to a Page other than Default.aspx , when implementing Form based authentication.





Responses

Author: John M. Joslin III    15 Mar 2007Member Level: Bronze   Points : 0
Regarding your article:

Forms Authentication - Redirecting users to a Page other than Default.aspx.

I looked at several hundred sites trying to find a solution for directing a user to a different page from a secure login. Your method worked like a champ!

Thank you very, very much!

John


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Error: "Parser Error Message: Could not load type 'WebApplication1.Global'." when browsing an asp.ne
Previous Resource: Handling Page Load Events and PostBack Issues
Return to Discussion Resource Index
Post New Resource
Category: Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use