RedirectFromLoginPage

S

Shawn

Hi.
I'm using RedirectFromLoginPage to redirect the user if the login was
successful. The problem is that I don't want the user to be redirected to
the page he requested. I want him to be redirected to my startup page. Is
that possible?


Thanks,
Shawn
 
C

Christopher Reed

Shawn,

When you authenticate the user, you can perform a Response.Redirect to your
startup page and just ignore the RedirectFromLoginPage method.

Hope this helps!

Christopher Reed
Web Applications Supervisor
City of Lubbock
"The oxen are slow, but the earth is patient."
Hi.
I'm using RedirectFromLoginPage to redirect the user if the login was
successful. The problem is that I don't want the user to be redirected to
the page he requested. I want him to be redirected to my startup page. Is
that possible?


Thanks,
Shawn
 
S

Shawn

If I simply replace RedirectFromLoginPage with Response.Redirect then the
page I'm redirecting to just sends me back to the login page again.. I'm
guessing I somehow have to tell FormsAuthentication that the user has been
authenticated.. Can you tell me how?

Shawn
 
C

Christopher Reed

Shawn,

Try this:

void LoginBtn_Click(Object sender, EventArgs e)
{
if (Page.IsValid)
{
// Call the authentication event handler delegate (not included
in this example).
if (FormsAuthentication.Authenticate(UserName.Text,
UserPass.Text))
{
// Return to the originally requested URL.
Response.Redirect("mystartpage.aspx");
}
else
{
Msg.Text = "Invalid Credentials: Please try again";
}
}
}

Hope this helps!


Christopher Reed
Web Applications Supervisor
City of Lubbock
"The oxen are slow, but the earth is patient."
If I simply replace RedirectFromLoginPage with Response.Redirect then the
page I'm redirecting to just sends me back to the login page again.. I'm
guessing I somehow have to tell FormsAuthentication that the user has been
authenticated.. Can you tell me how?

Shawn
 
Joined
Jul 22, 2009
Messages
1
Reaction score
0
No, no, no.

FormsAuthentication.RedirectFromLoginPage(string username, bool isCookiePersistent)

This method do two actions:
1. sets the authentication cookie to response so server reconize you in the future
2. redirects to requested or default page

If you do not want to redirect user to requested page, you can use Response.Redirect method instead, but before calling it you have to set auth cookie by executing:

FormsAuthentication.SetAuthCookie(string username, bool isCookiePersistent)

isCookiePersistent is true if you do not want authentication to expire in some time period, and default is false.

Why not FormsAuthentication.Authenticate?

Because, that method do only user credentials verification and you can use it only if you use web.config as user credential store.
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,743
Latest member
WoodrowMea

Latest Threads

Top