Tag: global asax

添加标头时在end_request中抛出exception

偶尔我会抛出这个exception(在elmah中可见) System.Web.HttpException: Server cannot append header after HTTP headers have been sent. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.Web.HttpException: Server cannot append header after HTTP headers have been sent. at System.Web.HttpHeaderCollection.SetHeader(String name, String value, Boolean replace) at System.Web.HttpHeaderCollection.Add(String name, String value) at BettingOnYou.MvcApplication.Application_EndRequest() in /Global.asax.cs:line 55 这一行对应于: protected void […]

在asp.net中关闭Global.asax中的文件/文件夹更改

防病毒扫描.Net部署的文件夹。 因此,应用程序会经常为客户注销。 需要大量批准才能在项目的文件夹级别获得豁免。 所以,我使用下面的代码: //FIX disable AppDomain restart when deleting subdirectory //This code will turn off monitoring from the root website directory. //Monitoring of Bin, App_Themes and other folders will still be operational, so updated DLLs will still auto deploy. System.Reflection.PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty(“FileChangesMonitor”, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static); object o = p.GetValue(null, null); System.Reflection.FieldInfo […]

“System.Web.HttpException:此上下文中的响应不可用”仅在IIS中

我在global.asax.cs Application Start中使用了Http.Current.Response 。 当我在我的电脑上执行时,它工作正常没有任何问题。 但是,当我尝试将其与Windows Server 2008 R2一起放入IIS时,我发现它发出以下错误。 它的代码是 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中执行。 谢谢

是否可以从ASP.NET 4.0中的服务器错误页面中删除信息?

为了更好地隐藏用户的信息,我试图从标准的ASP.NET错误屏幕中删除版本信息部分。 自定义错误已启用,但是,在某些情况下,如果您设法在控件之外发生错误(可能是服务器问题?),那么您可以进入YSOD。 我已经尝试更改web.config以包含httpruntime设置,您可以将enableVersionHeader设置为false,但版本信息仍然存在。 此外,在Application_PreSendRequestHeaders方法中,我尝试从响应标头中删除“X-AspNet-Version”,但由于web.config设置,该标头不存在。 在这种情况下我甚至想要什么?或者这些信息是否总是存在?

请求在此上下文中不可用 – >在Global.asax中 – >替换内容

为什么下面的行在global.asax中有错误: string RelativeFilePath = “~/” + (AbsoluteFilePath.Replace(Request.ServerVariables[“APPL_PHYSICAL_PATH”], String.Empty)).Replace(“\\”, “/”); 错误: 在此上下文中不提供请求 什么是替代品? 提前致谢

读取Global.asax中的HttpContext.Current.Response.OutputStream

我如何在Global.asax End_Request中读取HttpContext.Current.Response.OutputStream的全部内容? 我想获取发送到浏览器的内容文本? 我试着谷歌,但没有找到有用的东西。 实际上我希望这是可能的,我不需要为这个简单的要求创建一个filter或东西。 谢谢。

global.asax中的Application_Start()事件

海家伙,我的网站有成千上万的用户…我已经实现了每天一次向每个用户发送邮件的后台任务……我按照这个链接来做这个… http://www.codeproject.com/KB/aspnet/ASPNETService.aspx 我的问题是,每个用户点击我的网站都会触发Application_Start()…如果是这样,每个用户每天都会收到一些邮件,所以我想避免它……

Response.Redirect无法在Global.asax中工作

我创建了一个错误页面,显示所有未处理exception的常规消息。 这是Global.asax中的代码 HttpContext ctx = HttpContext.Current; string e404_PAGE = ctx.Request.AppRelativeCurrentExecutionFilePath.ToString(); string e404_LINE = ctx.Server.GetLastError().InnerException.StackTrace.Substring(ctx.Server.GetLastError().InnerException.StackTrace.LastIndexOf(“:line “) + 6, ctx.Server.GetLastError().InnerException.StackTrace.Substring(ctx.Server.GetLastError().InnerException.StackTrace.LastIndexOf(“:line “) + 6).IndexOf(” “)).ToString(); string e404_MESSAGE = ctx.Server.GetLastError().InnerException.Message.ToString(); string e404_METHODNAME = ctx.Server.GetLastError().InnerException.TargetSite.ToString(); string e404_STACKTRACE = ctx.Server.GetLastError().InnerException.StackTrace.ToString(); string e404_URL = ctx.Request.Url.ToString(); string e404_DATE = ctx.Timestamp.ToString(“yyyy-MM-dd HH:mm:ss”); string e404_USER = ctx.User.Identity.Name.ToString(); string e404_IP = ctx.Request.UserHostAddress.ToString(); // * * * […]

较小的更改后,Global.asax解析错误并恢复到以前的版本

上下文中的项目是: ASP .NET Web应用程序 .NET Framework:4 平台目标:x86 IDE:Visual Studio 2010 Ultimate SP1 解决方案中的多个项目,ASP .NET是启动项目。 它已经生产了几个月,直到昨天才出现故障。 我清理了[Global.asax]文件(删除了未使用的语句,重构等),运行解决方案并得到以下错误: 说明:解析为此请求提供服务所需的资源时发生错误。 请查看以下特定的解析错误详细信息并相应地修改源文件。 分析器错误消息:无法加载类型“CloudTech.ATS.WebClient.Global”。 源文件: /global.asax 行: 1 源错误:第1行: 这是Global.asax标记: 这是Global.asax.cs代码 (删除了内部代码): using System; using System.Linq; namespace CloudTech.ATS.WebClient { public class Global: System.Web.HttpApplication { } } 在与这个错误摔跤了一段时间后,我搜索,重新启动我的计算机,对解决方案执行了全面清理,强制重建但无济于事。 沮丧,我最终只将Web应用程序目标更改为“任何CPU”并且它有效。 不幸的是,“任何CPU”都不是手头问题的选择或解决方案。 将其更改回“x86”会带来相同的错误。 这发生一次,从那时起,目标平台或调试/发布配置的组合不再起作用(相同的错误)。 此外: 我的开发机器都是x64。 检查了解决方案,让多个同事在他们的机器(x86和x64)上进行测试,结果相同。 从3天前将整个项目恢复到干净状态,错误仍然存​​在! 绝对validation没有对Web.config文件或解决方案中的任何其他文件进行任何更改。 最后,我的开发系统的唯一变化是Windows更新(定期安全更新),我已经尝试了没有更新的系统上的解决方案,但结果相同。 任何帮助,将不胜感激。

Visual Studio 2010中的global.asax.cs在哪里

在我安装的模板中,我没有全局应用程序类代码隐藏。 我只有Global.asax。 我觉得使用Global.asax.cs更舒服。 为什么我不再看到它了? 如何重新创建Global.asax.cs?