" System.Web.HttpException:响应是在此上下文&QUOT可用;只有在IIS [英] "System.Web.HttpException: Response is not available in this context" only in IIS

查看:350
本文介绍了" System.Web.HttpException:响应是在此上下文&QUOT可用;只有在IIS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的global.asax.cs应用开始使用了 Http.Current.Response 。当我在我的电脑运行它没有任何问题,工作正常。如何过当我试图把它在IIS与Windows Server 2008 R2,我觉得这是给下面的错误。

i have used the Http.Current.Response in my global.asax.cs Application Start. It is working fine without any issue when i execute in my PC. How ever when i try to put it in IIS with Windows Server 2008 R2, i find that it is giving the following error.

有关它的代码是

public static void SetCookie(string key, string value, int dayExpires)
    {
        HttpCookie encodedCookie = HttpSecureCookie.Encode(new HttpCookie(key, value));
        encodedCookie.Expires = DateTime.Now.AddDays(dayExpires);

        HttpContext.Current.Response.Cookies.Remove(key);
        HttpContext.Current.Response.Cookies.Add(encodedCookie);
    }



我想描绘出它为什么在我的系统得到执行,但不在IIS。

I wanted to trace out why it is getting executed in my system, but not in IIS.

感谢

推荐答案

我不会做的请求/在回应面向的Application_Start事情。尝试在的BeginRequest 这样做。

I would not do request/response oriented things in Application_Start. Try doing it in BeginRequest.

这篇关于" System.Web.HttpException:响应是在此上下文&QUOT可用;只有在IIS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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