开发者

ControllerContext vs HttpContext in Azure

开发者 https://www.devze.com 2023-03-08 13:25 出处:网络
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

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 HttpContex开发者_如何学运维t.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.

0

精彩评论

暂无评论...
验证码 换一张
取 消