why the below line has error in global.asax :
为什么下面的行在全局上有错误。asax:
string RelativeFilePath = "~/" + (AbsoluteFilePath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty)).Replace("\\", "/");
Error :
错误:
Request is not available in this context
请求在此上下文中不可用
what is the replacement?
置换是什么?
thanks in advance
谢谢提前
2 个解决方案
#1
2
If you are hosting your application in IIS7 integrated pipeline HttpContext objects are not available in Application_Start
. For your scenario you could do this instead:
如果您正在IIS7集成管道中托管应用程序,则Application_Start中不能使用HttpContext对象。对于您的场景,您可以这样做:
string relativeFilePath = "~/" + AbsoluteFilePath
.Replace(HostingEnvironment.ApplicationPhysicalPath, String.Empty)
.Replace("\\", "/");
#2
0
In IIS7 or greater, the Integrated pipeline was introduced, and some rules changed. You cannot access the current HttpContext in Application_Start. Here's more information.
在IIS7或更大的情况下,引入了集成管道,并改变了一些规则。在Application_Start中无法访问当前的HttpContext。这里有更多的信息。
To quote, here's your options:
以下是你的选择:
So, what does this mean to you?
这对你来说意味着什么?
Basically, if you happen to be accessing the request context in Application_Start, you have two choices:
基本上,如果您碰巧在Application_Start中访问请求上下文,您有两个选择:
Change your application code to not use the request context (recommended). Move the application to Classic mode (NOT recommended).
将应用程序代码更改为不使用请求上下文(推荐)。将应用程序移动到经典模式(不推荐)。
Since you're just getting the application's physical path, I'd stick with Integrated Mode and just change your code.
因为您刚刚获得了应用程序的物理路径,所以我将坚持使用集成模式并只更改您的代码。
#1
2
If you are hosting your application in IIS7 integrated pipeline HttpContext objects are not available in Application_Start
. For your scenario you could do this instead:
如果您正在IIS7集成管道中托管应用程序,则Application_Start中不能使用HttpContext对象。对于您的场景,您可以这样做:
string relativeFilePath = "~/" + AbsoluteFilePath
.Replace(HostingEnvironment.ApplicationPhysicalPath, String.Empty)
.Replace("\\", "/");
#2
0
In IIS7 or greater, the Integrated pipeline was introduced, and some rules changed. You cannot access the current HttpContext in Application_Start. Here's more information.
在IIS7或更大的情况下,引入了集成管道,并改变了一些规则。在Application_Start中无法访问当前的HttpContext。这里有更多的信息。
To quote, here's your options:
以下是你的选择:
So, what does this mean to you?
这对你来说意味着什么?
Basically, if you happen to be accessing the request context in Application_Start, you have two choices:
基本上,如果您碰巧在Application_Start中访问请求上下文,您有两个选择:
Change your application code to not use the request context (recommended). Move the application to Classic mode (NOT recommended).
将应用程序代码更改为不使用请求上下文(推荐)。将应用程序移动到经典模式(不推荐)。
Since you're just getting the application's physical path, I'd stick with Integrated Mode and just change your code.
因为您刚刚获得了应用程序的物理路径,所以我将坚持使用集成模式并只更改您的代码。