I have some logic in Session_Start
and this logic is actual for all my controller methods except one special method. I need to not execute Session_start
logic, when user goes to special method URL.
Any ideas how I can do that?
I have some logic in Session_Start
and this logic is actual for all my controller methods except one special method. I need to not execute Session_start
logic, when user goes to special method URL.
Any ideas how I can do that?
As far as I understand your question, you do not want the code within your Session_Start method to be invoked if a special url is requested. I think it would be helpful to know what your problem is, that you want to solve. For now here is my answer:
Since Session_Start is only invoked once (at least usually, depending on your configuration of the session module - see my comments to your question), this only works if the client invokes the "special" url first, e.g. before calling other urls. If another url has been invoked first, session will be initialized according to your code. Important: as mentioned, depending on your configuration, there will be always a Session (but in this special case you do not want to execute your custom logic in Session_Start):
You can use the Current HttpRequest and perform a check on some properties:
// this will (usually) only be called once, on the first request of the client
protected void Session_Start() {
// perform your check here if this is the url you want to exclude
if (HttpContext.Current.Request.Url.OriginalString.ToLowerInvariant().EndsWith("something")) {
return;
}
// your initialization here that should not be executed for clients accessing the site using the above url
}
As you can see, you can access the Request object, and perform your check there, depending on your requriements.