Do Stuff Every Request
say i want to update the login table everytime the user makes any request
scenario 1: no webmethods or ajax:
from the great collection of events in Global Asax we have 3 that fires with each request And knows the Session:
void Session_Start(object sender, EventArgs e){}
void Application_AcquireRequestState(object sender, EventArgs e){}
*here is ur code like pageload ect. btw
void Application_PostRequestHandlerExecute(object sender, EventArgs e){}
so in any of those i can put an sql query and use Session.SessionID or Session["myvar"]
NOTE! that since only PostRequest is executed after ur page finished his code that any changes made to the Session will only appear to him. Also in the very 1st run it will always be empty.
scenario 2: webmethods or ajax:
well i only tested that with page webmethods and PageMehtods, $.ajax and $.post client side.
i found out a few nice thing, fisrt of all from these 3 event only
Application_AcquireRequestState is fired.
on a side note i also found out how to recognize requests - with
Request.Headers, currently i'll just put the expample of skipping if its a JQ:
//jquery: Accept: application/javascript, */*;q=0.8
//ajax to webmethod: Accept: application/json, text/javascript, */*; q=0.01
if (Request.Headers["Accept"] != null
&& Request.Headers["Accept"].Contains("javascript")
&& !Request.Headers["Accept"].Contains("json"))
return;
thx fiddler!
scenario 1: no webmethods or ajax:
from the great collection of events in Global Asax we have 3 that fires with each request And knows the Session:
void Session_Start(object sender, EventArgs e){}
void Application_AcquireRequestState(object sender, EventArgs e){}
*here is ur code like pageload ect. btw
void Application_PostRequestHandlerExecute(object sender, EventArgs e){}
so in any of those i can put an sql query and use Session.SessionID or Session["myvar"]
NOTE! that since only PostRequest is executed after ur page finished his code that any changes made to the Session will only appear to him. Also in the very 1st run it will always be empty.
scenario 2: webmethods or ajax:
well i only tested that with page webmethods and PageMehtods, $.ajax and $.post client side.
i found out a few nice thing, fisrt of all from these 3 event only
Application_AcquireRequestState is fired.
on a side note i also found out how to recognize requests - with
Request.Headers, currently i'll just put the expample of skipping if its a JQ:
//jquery: Accept: application/javascript, */*;q=0.8
//ajax to webmethod: Accept: application/json, text/javascript, */*; q=0.01
if (Request.Headers["Accept"] != null
&& Request.Headers["Accept"].Contains("javascript")
&& !Request.Headers["Accept"].Contains("json"))
return;
thx fiddler!
Thanks for sharing, nice post! Post really provice useful information!
ReplyDeleteAn Thái SÆ¡n chia sẻ trẻ sÆ¡ sinh nằm nôi Ä‘iện có tốt không hay võng Ä‘iện có tốt không và giải đáp cục Ä‘iện Ä‘Æ°a võng giá bao nhiêu cÅ©ng nhÆ° mua máy Ä‘Æ°a võng ở tphcm địa chỉ ở đâu uy tÃn.