Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

FormsAuthentication doesn't automatically redirect upon timeout

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
christine.nguyen@gmail.com - 05 Feb 2008 16:49 GMT
I am using Forms Authentication under Windows Server 2003 in .NET
2.0.  It appears that the auth ticket is expiring when it's supposed
to but it doesn't automatically redirect the user to the login page.
Here is some watered down sample code I had to put in the onLoad of my
page in order to properly redirect the user upon expiration of the
login.  It appears that once the auth ticket is expired, the name of
the Identity is lost (which makes sense) and then I redirect the user.

protected override void OnLoad(EventArgs e)
 string userName = HttpContext.Current.User.Identity.Name;
 if(String.IsNullOrEmpty(userName)
     Response.Redirect(redirectUrl);
}

My question is whether I really have to include such code in my page
to handle the the empty Identity name or should the framework be
redirecting on its own once the auth ticket has expired and the
identity name is empty?

Thanks,
Christine
Coskun SUNALI [MVP] - 05 Feb 2008 17:17 GMT
Hi Christine,

Normally, you don't have to implement the redirection by yourself.
Specifiying the login url should solve your problem. By doing that, the user
must be automatically redirected to the login page at his/her first request
to a secured path.

<forms name=".aspxlogin" loginUrl="~/Login.aspx" />

Signature

All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk

>I am using Forms Authentication under Windows Server 2003 in .NET
> 2.0.  It appears that the auth ticket is expiring when it's supposed
[quoted text clipped - 17 lines]
> Thanks,
> Christine
christine.nguyen@gmail.com - 05 Feb 2008 23:29 GMT
Hello,

I do specify the login url in web.config, but for whatever reason it
doesn't redirect upon timeout when a secured resource is accessed.
Instead it throws an exception when I try to access and use the value
in HttpContext.Current.User.Identity.Name (which is now empty). This
is why i put code into the onLoad in order to prevent the exception.
Is there a reason why it wouldn't redirect even though I have the
login url specified in web.config?

Thanks,
Christine
Coskun SUNALI [MVP] - 06 Feb 2008 10:13 GMT
Hi,

Yes. If you have a HttpModule that logs and then cleans the errors on the
server, ASP.NET doesn't redirect.

Signature

All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk

> Hello,
>
[quoted text clipped - 8 lines]
> Thanks,
> Christine
Coskun SUNALI [MVP] - 06 Feb 2008 10:48 GMT
Hi,

Sorry for my previous message. It has nothing to do with your problem.

Can you please attach a project in a zip file to reproduce the problem you
have.

I will try to correct it and send it back.

Signature

All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk

> Hi,
>
[quoted text clipped - 13 lines]
>> Thanks,
>> Christine

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.