문제

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!

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top