0

I am developing an user authentication site. I have a login page, "Login.aspx" in which i have provided a login control. In the web.config,

<authentication mode="Forms">
        <forms name=".AuthenticationCookie" loginUrl="Login.aspx"  protection="All" timeout="60" path="/">
            <credentials passwordFormat="Clear">
                <user name="Jack" password="Jerry"/>
            </credentials>
        </forms>
    </authentication>
    <authorization>
        <deny users="*"/>
    </authorization>

In the login.aspx.cs page, I have provided,

 protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        if (FormsAuthentication.Authenticate(Login1.UserName,Login1.Password))
        {
             FormsAuthentication.SetAuthCookie(Login1.UserName,true);
            Label1.Text = "Login Successful";
            Login1.InstructionText = "";
            FormsAuthentication.RedirectFromLoginPage(Login1.UserName, true);
            Response.Redirect("Success.aspx")

        }
        else
        {
            Label1.Text = "You are not an authentic user";
        }


    }
}

but however, while execution instead of going to success.aspx with the url http://localhost/Login.aspx?ReturnUrl=%2fSuccess.aspx

Why is this so?

5
  • I don't understand what it's doing. You say "while execution instead of going to success.aspx ..." What is it doing "instead of" that? Commented Jul 8, 2010 at 12:32
  • sorry 4 dat.... instead of that it remains in Login.aspx with the above specified url. Commented Jul 8, 2010 at 12:39
  • In your above code, now that it's using RedirectFromLoginPage, you should remove the SetAuthCookie and Response.Redirect calls. After you do that, if it's still having the same problem, what do you see when you step through it in the debugger. Does the FormsAuthentication.Authenticate call succeed? If so, does it make it to the RedirectFromLoginPage call? What HTTP traffic do you see (use Fiddler - fiddler2.com/fiddler2). Commented Jul 8, 2010 at 15:36
  • thank you.. problem is solved :) Commented Jul 9, 2010 at 5:10
  • It would be helpful to others if you explained what solved the problem (plus I'm curious ;). Commented Jul 9, 2010 at 14:41

1 Answer 1

1

If you want to set the forms auth cookie yourself and redirect correctly based on the ReturnUrl query string parameter, you should look at the FormsAuthentication.RedirectFromLoginPage method. In your example, it would be:

FormsAuthentication.RedirectFromLoginPage(Login1.UserName, true);

That method sets the appropriate Forms auth cookie / ticket and then redirects based on the presence or absence of the ReturnUrl parameter. (If absent, it goes to the configured default page.)

Hope this helps,

Donnie

Sign up to request clarification or add additional context in comments.

2 Comments

ya..i did it..and the modified code is given above. but the output remains the same.
Thanks for tip.. Actually, running into the same problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.