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! 
 


Comments

Popular posts from this blog

c# Service Play Sound with NAudio example by Moshe

SOLVED The item could not be indexed successfully because the item failed in the indexing subsystem

JS/JQ simulate Enter event