在Application_Start事件Request对象 [英] Request object in Application_Start event

查看:188
本文介绍了在Application_Start事件Request对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前使用这行代码来获得在Application_Start事件中的当前应用程序的URL。

We currently use this line of code to get the current applications url in the Application_Start event.

string sApplicationURL = HttpContext.Current.Request.Url.Scheme + "://" 
                         + HttpContext.Current.Request.Url.Authority 
                         + HttpContext.Current.Request.ApplicationPath;



我刚刚发现,在IIS7.0请求对象不再可用时,Application_Start事件被激发。

I just recently found out that in IIS7.0 the Request object is no longer available when the Application_Start event is fired.

有另一种方式来获得当前应用程序的URL,而无需使用Request对象?

Is there another way to get the current applications url without using the Request object?

感谢

推荐答案

有一个看看这个:
http://mvolo.com/blogs/serverside/archive /2007/11/10/Integrated-mode-Request-is-not-available-in-this-context-in-Application_5F00_Start.aspx

在综上所述,由于请求上下文不再提供给Application_Start事件发生错误。该博客指出两个选择来处理此错误:

In summary, the error occurs because the Request context is not longer available to the Application_Start event. This blog states two choices to deal with this error:

1)改变你的代码工作W / O请求,或者
2)修改您的应用程序运行在经典模式(不推荐)。

1) Change your code to work w/o Request, or 2) Modify your application to run in Classic Mode (not recommended).

要获得ApplicationPath,使用 HttpRuntime.AppDomainAppVirtualPath

To get the ApplicationPath, use HttpRuntime.AppDomainAppVirtualPath.

这篇关于在Application_Start事件Request对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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