Why is this web api controller not concurrent?

后端 未结 5 831
旧巷少年郎
旧巷少年郎 2020-12-01 08:32

I have a Web API Controller with the following method inside:

public string Tester()
{
    Thread.Sleep(2000);

    return \"OK\";
}

When I

5条回答
  •  庸人自扰
    2020-12-01 08:59

    You must have enabled the Session State somewhere for Web Api. Web API is restful by default and has no session. Check your global.asax Application_AuthenticateRequest section (this is where I enable session state for Web Api). Find where you enabled your session state at and set it to read-only mode to allow for parallelism on web methods using session state. See this question which is similar: Web API Service - How to make the requests at the server to be executed concurrently

    Look for something like this:

    HttpContext.Current.SetSessionStateBehavior(System.Web.SessionState.SessionStateBehavior.Required);
    

    Change it to this:

    HttpContext.Current.SetSessionStateBehavior(System.Web.SessionState.SessionStateBehavior.ReadOnly);
    

提交回复
热议问题