Question : FormsAuthentication.Redire<wbr />ctFromLogi<wbr />nPage question

Hi

I have login.asp.cs which contains the code below.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void cmdLogin_Click(object sender, EventArgs e)
    {
        if (txtPassword.Text.ToLower() == "secret")
        {
            FormsAuthentication.RedirectFromLoginPage(txtName.Text, false);
        }
        else
        {
            lblStatus.Text = "Try again.";
        }
    }
}

When I run this code, this code goes to Default.aspx page automatically.
In my Web.config file, loginUrl is set to "Login.aspx".  So all the unauthenticated request will go to Login.aspx page, right?
And as I know, loginUrl's default value is Default.aspx.
1) How does the application lead a user to default.aspx page when a user enters correct pwd?

Now I created SecuredPages folder under my current project and then created SecuredPages.aspx under this folder.  That's all I did.
2) Now when I run the application and if my pwd is correct, the application redirects me to the SecuredPages.aspx.  What's going on here?  and why do I need to created SecuredPage folder in this example?

Thanks!

Answer : FormsAuthentication.Redire<wbr />ctFromLogi<wbr />nPage question

--->In my Web.config file, loginUrl is set to "Login.aspx".  So all the unauthenticated request will go to Login.aspx page, right?
Yes, provided you have set authorization in web.config to deny anonymous(?) users.

1) How does the application lead a user to default.aspx page when a user enters correct pwd?
defaultUrl is the attribute that results into redirect to default.aspx if no ReturnUrl is present in the querystring. Its default value is "default.aspx". Check the link below:
http://msdn.microsoft.com/en-us/library/1d3t3c61.aspx

2) Now when I run the application and if my pwd is correct, the application redirects me to the SecuredPages.aspx.  What's going on here?  
---> Here ReturnUrl in the querystring of your url is playing some role here.
Say you directly navigate to Login.aspx via a link then the ReturnUrl should be empty and you will be taken to defaultUrl after authentication.
But say your try to access SecuredPage.aspx then you will first be taken to login.aspx with ReturnUrl querystring parameter added to your login.aspx url. Upon successful login your will be redirected to the ReturnUrl i.e. Securepage.aspx

---->and why do I need to created SecuredPage folder in this example?
can you explain that a bit.

Random Solutions  
 
programming4us programming4us