asp.net – 在集成模式下替换HttpContext.Current.Request.Serve
发布时间:2020-12-16 00:14:27 所属栏目:asp.Net 来源:网络整理
导读:在集成模式下使用HttpContext.Current.Request.ServerVariables [“SERVER_NAME”]会在IIS7中出现错误,如下所示: http://mvolo.com/blogs/serverside/archive/2007/11/10/Integrated-mode-Request-is-not-available-in-this-context-in-Application_5F00_St
在集成模式下使用HttpContext.Current.Request.ServerVariables [“SERVER_NAME”]会在IIS7中出现错误,如下所示:
http://mvolo.com/blogs/serverside/archive/2007/11/10/Integrated-mode-Request-is-not-available-in-this-context-in-Application_5F00_Start.aspx
我可以在global.asax代码中使用HttpContext.Current.Request.ServerVariables [“SERVER_NAME”]吗? 这与使用类似 String strPath = HttpContext.Current.Server.MapPath(HttpRuntime.AppDomainAppVirtualPath); 代替 //String strPath = HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ServerVariables["PATH_INFO"]); 解决方法
由于在应用程序启动期间管道中没有请求上下文,我无法想象有什么方法可以猜测下一个实际请求可能出现在哪个服务器/端口上.
这是我在经典模式下使用的内容.开销可以忽略不计. /// <summary> /// Class is called only on the first request /// </summary> private class AppStart { static bool _init = false; private static Object _lock = new Object(); /// <summary> /// Does nothing after first request /// </summary> /// <param name="context"></param> public static void Start(HttpContext context) { if (_init) { return; } //create class level lock in case multiple sessions start simultaneously lock (_lock) { if (!_init) { string server = context.Request.ServerVariables["SERVER_NAME"]; string port = context.Request.ServerVariables["SERVER_PORT"]; HttpRuntime.Cache.Insert("basePath","http://" + server + ":" + port + "/"); } } } } protected void Session_Start(object sender,EventArgs e) { //initializes Cache on first request AppStart.Start(HttpContext.Current); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 是否可以完全在代码中配置ELMAH?
- asp.net – 为什么Web API请求的正文读取一次?
- VS 2012中解决方案资源管理器中的asp.net配置按钮在哪里
- asp.net-mvc – ASP.NET MVC路由中未传递的参数值
- asp.net-mvc – 为什么我需要在asp.net mvc中部分视图的下划
- Favicon只在主页ASP.NET MVC中显示
- 如何为高使用率的ASP.NET应用程序重新平衡SQL Server 2008?
- asp.net – 当主机名中有下划线时,表单身份验证无法识别为在
- 如何在ASP.NET中用C#编程设置(使用GET SET属性)“httpRunti
- 缺少版本和工具:.NET Core,Core Tools,dotnet Core CLI,
推荐文章
站长推荐
热点阅读