Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

ASP.NET: Why is FormsAuthenticationTicket null after authentication timeout? -


i'm implementing authentication timeout detection mechanism per previous question , answer of mine here. i've implemented http module uses authenticaterequest event run code capture whether authentication period has expired. code below:

public class authenticationmodule : ihttpmodule {     #region ihttpmodule members     void ihttpmodule.dispose() { }     void ihttpmodule.init(httpapplication application)     {         application.authenticaterequest += new eventhandler(this.context_authenticaterequest);     }     #endregion       /// <summary>     /// inspect auth request...     /// </summary>     /// <remarks>see "how implement iprincipal" in msdn</remarks>     private void context_authenticaterequest(object sender, eventargs e)     {         httpapplication = (httpapplication)sender;         httpcontext context = a.context;          // extract forms authentication cookie         string cookiename = formsauthentication.formscookiename;         httpcookie authcookie = context.request.cookies[cookiename]; // no longer forms cookie in array once timeout has expired          if (authcookie != null)         {             formsauthenticationticket authticket = formsauthentication.decrypt(authcookie.value);             datetime expirationtime = authticket.expiration;             // check if authenticated session dead             if (authticket != null && authticket.expired)             {                 // send them response indicating they've expired.             }         }     } } 

the problem that, once authentication period has expired (i set 1 min test), there no longer forms cookie (see comment in code). means authentication cookie null, , won't make past null check in code. there's convenient "expired" property formsauthenticationticket feel should checking see if period expired. how far if cookie no longer there? reasonable assume authentication period has expired if there's no longer forms cookie?

any appreciated on this.

you might want try this:

if (user != null)         {             formsidentity id = (formsidentity)user.identity;             formsauthenticationticket ticket = id.ticket;             if (ticket.expired)             {                //do             }         } 

more info

edit:

1: see user null. using user.identity out of question.

2: how trying code have in original question in beginrequest event instead of authenticaterequest.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -