0

I need to store some information in session(or in whatever in ASP.NET Web API) that I need to retrieve in each API request. We will have one api IIS web site and multiple web site binding will be added through host header. When any request comes in for example, api.xyz.com, host header will be checked and store that website information in session that will be used in each subsequent api request when making a call to database. Hope this is clear.

I found a way to handle session in ASP.NET Web API. ASP.NET Web API session or something?.

I know lot more about asp.net web forms where we can override PreRequestHandler. I am looking for similar in ASP.NET Web API where I can have my logic to get database id for api domain(for example, api.xyz.com) and store it in session which I want to access in each API GET/POST request.

Somebody will definitely say by adding session I am making it stateful but REST is stateless. But I wanted to save database trip for each api request. If I don't use session or something similar, I end up repeating the same logic for each api request.

Is there a better way to handle this situation? how?

thanks.

Community
  • 1
  • 1
user1186065
  • 1,847
  • 3
  • 17
  • 22

1 Answers1

1

If that logic needs to happen for all requests, you better use an Implementation of delegating handlers.

Aliostad
  • 80,612
  • 21
  • 160
  • 208