Question

I'm wondering if there are any implications between using ControllerContext as opposed to HttpContext, in an Azure setting. I've found that HttpContext is thread static, and I'm trying to find out if this is relevant in Azure or not.

Assuming there is no real difference, can I guarantee that the two will be equal when a controller action is called? I'm attempting to write unit tests for an established application which makes some calls to HttpContext.Current in controller actions. In some places throughout the app changes are made directly to HttpContext.Current (specifically as part of authorization). If I switch over to ControllerContext, will changes made to HttpContext.Current be reflected?

Thanks!

Était-ce utile?

La solution

They're not quite the same thing - but if you happen to be calling them both on the same incoming thread from a web call then they will indeed both provide mechanisms to access the same HttpContext instance.

See this question and answer - Difference between HttpContext.Current and Controller.Context in MVC ASP.NET.

For testability, it is good to move to ControllerContext if you can.

Autres conseils

Regarding ControllerContext vs HttpContext, I have no idea. I just know that Windows Azure has no bearing on it. Windows Azure runs Windows and IIS7 - so, whatever the answer is for your on-premises decision applies equally to the cloud.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top