ASP.NET的HttpContext物品消失在服务器上 [英] ASP.NET HttpContext Items vanish on server

查看:108
本文介绍了ASP.NET的HttpContext物品消失在服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前看到的问题与使用 HttpContext.Current.Items 其中,开发商的当地环境显示服务器没有问题(如预期所有的作品)环境我们突然放松放在里面的物品(获得一个的NullReferenceException )。

We are currently seeing an issue with the use of HttpContext.Current.Items where the local environments of the developers show no issues (all works as expected) in the server environment we are suddenly loosing items placed inside (getting a NullReferenceException).

我勾画了一些code及以下用途:

I sketched some code and use below:

Global.asax中我们初始化出厂时的BeginRequest:

Global.asax we initialise the factory at BeginRequest:

protected void Application_BeginRequest(object sender, EventArgs e)
{
    HttpContext.Current.Items["Key"] = new Factory();
}

BASECONTROL 我们有一个属性来方便地检索工厂:

Inside the BaseControl we have a property to retrieve the factory easily:

public Factory Factory
{
    get { return HttpContext.Current.Items["Key"] as Factory; }
}

用户控件我们使用它通过基本属性:

In the UserControl we use it through the base property:

protected void Page_Load(object sender, EventArgs e)
{
    Product p = Factory.CreateProduct();
}

环境信息:


  • 本地的DEV使用的是IIS 7.5和8 Sitecore的6.6在Windows 7和8上运行

  • 服务器正在运行Windows Server 2008 R2使用的是IIS 7.5和6.6 Sitecore的

有关所有本地的DEV(我们在做这个项目有6人)有与上述code无问题。然而,一旦我们部署code到测试服务器使用该工厂休息的位置(EA的 HttpContext.Current.Items 为空)

For all local DEVs (we're working on this project with 6 people) there's no issue with the code described above. However once we deploy the code to the test server the locations that use the Factory break (ea the HttpContext.Current.Items is empty)

推荐答案

我注意到你的财产使用相同的名称,因为它的类型:

I noticed you use the same name for your property as it's type:

public Factory Factory {}

也许这引发一些意想不到的行为?

Maybe this initiates some unexpected behavior?

这篇关于ASP.NET的HttpContext物品消失在服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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