login and Default.aspx page
-
Hi all, Im coming to the end of my project and my last prob is this! When a user goes directly to the login page and enters correct details in, they get redirected to the 'Default.aspx' page, I want them to be redirected to the 'Home.aspx' page. The question is , how to change the 'Default' page to 'home' page. I want to keep using the FormsAuthentication.RedirectFromLoginPage(customerId, True) Because i dont want the user to ALWAYS be directed to the Home page. Thanks in advance Jetset!
-
Hi all, Im coming to the end of my project and my last prob is this! When a user goes directly to the login page and enters correct details in, they get redirected to the 'Default.aspx' page, I want them to be redirected to the 'Home.aspx' page. The question is , how to change the 'Default' page to 'home' page. I want to keep using the FormsAuthentication.RedirectFromLoginPage(customerId, True) Because i dont want the user to ALWAYS be directed to the Home page. Thanks in advance Jetset!
Hi there, IMHO, you first need to understand how the
FormsAuthentication.RedirectFromLoginPage
method works. Basically, the method will redirect the user to the originally requested page specified in the query string with theReturnUrl
key. If this key is not found, the user is always redirected to theDefault.aspx
at root. Here, you want to keep using this method, so IMO there are a couple of options come to mind: + If you want the user to be redirected to his originally requested page, you first check if theReturnUrl
key exists in the query string before calling theRedirectFromLoginPage
. If the key does not exist, you can use theResponse.Redirect
method to go to the home.aspx page. If you don't want to do the checking, you can simply create a default.aspx at root, in this default page, you simply redirect the user to your home page home.aspx. + If you want the user to always be directed to the home.aspx page, you should use the Response.Redirect method instead of the FormsAuthentication.RedirectFromLoginPage. Or you can think of removing theReturnUrl
key in the query string with the sample code like this in the Page_Load event handler of the login page:private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack && Request.QueryString["ReturnUrl"]!=null)
{
Response.Redirect(Request.Url.AbsolutePath);
}
}For more information, see RedirectFromLoginPage [^]