Igor Konopko
Igor Konopko

Reputation: 764

.Net Web Api multiple requests at once

I want to enable making several concurrent requests to server from a single client. How can this be done with .Net WebApi? In ASP.Net MVC 3 it could be enabled with adding the follow attribute to the controller:

[SessionState(SessionStateBehavior.ReadOnly)]
public class SomeController : AsyncController
{
  //.....
}

Information about MVC Session was found here:

The Downsides of ASP.NET Session State

But in Web Api application it doesn't work. I've also accessing session data like in this question:

Accessing Session Using ASP.NET Web API

So, I think thats why I can't make multiple requests at once from client. What should I do enable that feature?

Upvotes: 0

Views: 4228

Answers (2)

Igor Konopko
Igor Konopko

Reputation: 764

Resolved by adding:

void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e)
        {
            HttpContext.Current.SetSessionStateBehavior(
                SessionStateBehavior.ReadOnly);
        }

and

public override void Init()
        {
            PostAuthenticateRequest += MvcApplication_PostAuthenticateRequest;
            base.Init();
        }

to Global.asax

Upvotes: 2

Cybermaxs
Cybermaxs

Reputation: 24556

Yes, there are a lot of problems with using session in your ASP.NET applications. Moreover, by default, HTTP (and by extension, REST- like/style application) is stateless – and as a result each HTTP request should carry enough information by itself for its recipient to process it to be in complete harmony with the stateless nature of HTTP.

Web Api was not design to support Asp.net Session ; you have nothing else to do. So, If you need some information in a Web Api, do not rely on Seesion State but add them into your request

What is very funny, is that some people want to support Session in Web Api ...

Upvotes: 1

Related Questions