activebiz
activebiz

Reputation: 6230

Azure web application (webapi) in Web Farm / Load balancing

WebForm : In webform (with session) state application in web farm environment the session is stored in SQL Server storage which can be accessed by all the servers in a webfarm. This means the logged in user's request can get the same session regardless of which server in the farm it hits.

WebAPI : I understand that webapi by design is stateless so for true webapi application I dont need to worry about how the state is maintained etc. Usually the authentication token is passed between requests and as far as its valid a login gets access to the whatever resource it needs on the server. This is fine with one Webserver hosting webapi. But what about web farm. How does the "Session" (Or the equivalent term in Webapi) is managed in WebApi farm?

I know azure gives following options to name the few.. Azure SQL Server Azure Table storage /Queue Cache Service

They seems to add extra complexity to the architecture (which is much easier in WebForm using SQL Server Session).

One other slightly different question (and might a bit basic) is how does the request/response is traced in webapi farm? i.e. When a client make request to webapi and webapi sends a async response how does server make sure its traced back to the client?

Edit: I am not looking to implement Session is Webapi but rather how the same thing can be achieved in webapi without session state.

Thanks

Upvotes: 0

Views: 743

Answers (1)

Michael Sync
Michael Sync

Reputation: 4994

Yes. Using session in REST is a really bad thing.

But you can simulate the session in Web API as well. In web form, the server added the generated session id in HTML from so when user submit that session id will be included in their request. You can simulate the same thing with Web API as well. You can check this Accessing Session Using ASP.NET Web API

The best that you can store the information in memcached or redis with expiration. It will work in web farm as well.

Anyways, I don't recommend using the "session" in Web API.

Upvotes: 1

Related Questions