做一个HTTP POST到一个ASHX时,打破了.NET 4.5 CallContext中变化? [英] Breaking Change in .net 4.5 Callcontext when doing a HTTP Post to an ashx?

查看:152
本文介绍了做一个HTTP POST到一个ASHX时,打破了.NET 4.5 CallContext中变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装了.NET 4.5,发现现有的Web应用程序,这仍然是.NET 4.0下运行时,当我试图找回从CallContext中,一个项目失败时,安装之前可以正常使用并已在去年完成的。

I've just installed .Net 4.5 and noticed that an existing web application, that is still running under .Net 4, is failing when I'm trying to retrieve an item from the CallContext, when before the install was working perfectly and has done for the last year.

在应用程序的的AuthenticateRequest事件中,我们使用的用户的身份来加载关于用户更多的安全信息。这被添加到该CallContext中供以后使用。

On the AuthenticateRequest event of the application, we use the Identity of the user to load more security information about the user. This is then added to the CallContext for later use.

例如

 protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated)
        { 
             // set someValue 
            CallContext.SetData(ContextIdentifier, someValue);
        }
    }

在CallContext中的值是在生命周期后分检索。例如
    CallContext.GetData(ContextIdentifier)

The value in the callcontext is retrieved at later points in the lifecycle. e.g CallContext.GetData(ContextIdentifier)

不过,从HTTP请求.ashx的POST请求时,该值是零,现在却在GET请求中的值是正确的。

However, when requesting an .ashx from a http "POST" request, the value is now null but on a "GET" request the value is correct.

我找不到记载之所以出现这种突然变化或这是否是现在的设计,为什么它会影响现有的.NET 4应用程序?

I can't find an documented reason why this has suddenly changed or whether this is now by design and why it would affect existing .Net 4 applications?

我明显的解决方法是也提上了HttpContext的数据,但不理解为什么我不能确定是否使用CallContext中会引起其他的问题!

My obvious fix is to also put the data on the HTTPContext, yet without understanding the reason why I'm unsure if using the CallContext will cause issues elsewhere!

任何帮助/理解将感激收到

Any help / understanding would be gratefully recieved

推荐答案

<一个href=\"http://forum.springframework.net/showthread.php?572-CallContext-vs-ThreadStatic-vs-HttpContext\" rel=\"nofollow\">http://forum.springframework.net/showthread.php?572-CallContext-vs-ThreadStatic-vs-HttpContext

看来,这是HTTP管道处理调用上下文,但我一定要看到只有现在,因为改进

It appears that it was the http pipeline disposing of the call context but I must be only seeing it now because of improvements

这篇关于做一个HTTP POST到一个ASHX时,打破了.NET 4.5 CallContext中变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆