Readonly access to session in a web service call

asp.netsession-stateweb serviceswebforms

We have a .net asmx web service that gets called from javascript (using ASP.Net AJAX), and requires access to Session.

[WebMethod(true)]
public string DoSomethingOnTheServer() { }

We're running into the problem of session being locked on a read/write request. Is there any way to mark a web service method as requiring read-only access to Session?

Thanks!

Best Answer

This is a really old thread, but i stumbled on it in my search for an answer to the same question.

I found the answer else where, and will leave it here for other internets in my place:

In Global.asax you can specify for each request, what access the request should have to the session object, and thereby if it should block or not.

private void Application_BeginRequest(object sender, EventArgs e)
{
    // This will set the session to read only for asmx services
    // This will make the asmx services non blocking for other requests as it doesnt lock the session object
    if (Context.Request.Path.Contains(".asmx/"))
    {
        Context.SetSessionStateBehavior(SessionStateBehavior.ReadOnly);
    }
}

This way asmx services always only have read only access to the session and will not block other requests