Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > Solution to Forms Authentication redirecting to bogus default.aspx page with RedirectFromLoginPage

Reply
Thread Tools

Solution to Forms Authentication redirecting to bogus default.aspx page with RedirectFromLoginPage

 
 
Tim_Mac
Guest
Posts: n/a
 
      05-11-2005
hi,
i've read a lot of posts here about people who ran into problems using
forms authentication, and the RedirectFromLoginPage() method, which
always redirects to a default.aspx. this is a big problem if you use
sub-folders that don't have a default.aspx page, as in my case.
i read some posts that suggested manually Response.Redirecting the user
to the url in the querystring, but actually this is incorrect because
Forms Auth puts the default.aspx in that querystring even if the user
wasn't at a page called default.aspx.

i put together a simple solution to get the redirecting to work
properly, and would like to post it here for future reference:

1. the Login page (Login.aspx) must be set up to read the
HTTP_Referrer, and add it to the ViewState in the first Page_Load on
that page.

2. in the btnLogin_Click event on Login.aspx, the SetAuthCookie() event
should be called, and the user should be Response.Redirected to the
referrer value in the viewstate.

Here is sample code:

*****************
Login.aspx
*****************

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
ViewState["originalUrl"] = Request.UrlReferrer.AbsoluteUri;
}

private void btnLogin_Click(object sender, System.EventArgs e)
{
string originalUrl = ViewState["originalUrl"];
if(originalUrl == null || originalUrl == "") // in case the viewstate
is corrupt, use default.aspx by 'default'
originalUrl = "default.aspx";

// do your password checking here
// if it's all ok then...
FormsAuthentication.SetAuthCookie(username, false);
Response.Redirect(originalUrl, true);
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FormsAuthentication.RedirectFromLoginPage is not redirecting to the correct page. Jeremy Chapman ASP .Net 1 09-21-2005 09:39 PM
RedirectFromLoginPage not redirecting to RedirectUrl jjjooooohhnnn@mail.com ASP .Net 4 03-01-2005 06:02 AM
not redirecting to login page while using forms authentication Pradeep Pise ASP .Net 0 07-09-2004 07:27 AM
RedirectFromLoginPage not redirecting sean ASP .Net Security 6 05-21-2004 04:21 AM
without Forms authentication.redirectFromLoginPage()? .NET Follower ASP .Net 2 02-04-2004 05:15 AM



Advertisments