请求是不是在这方面可用 - >在Global.asax中 - >什么是替代 [英] Request is not available in this context -> In Global.asax -> what is replace

查看:154
本文介绍了请求是不是在这方面可用 - >在Global.asax中 - >什么是替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么下面的线路有错误在Global.asax中:

why the below line has error in global.asax :

string RelativeFilePath = "~/" + (AbsoluteFilePath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty)).Replace("\\", "/");  

错误:

请求不可用在这种情况下

Request is not available in this context

什么替代?

在此先感谢

推荐答案

如果您承载IIS7中的综合管线HttpContext的应用程序对象不在的Application_Start 可用。对于您的情况,你可以这样做,而不是:

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:

string relativeFilePath = "~/" + AbsoluteFilePath
    .Replace(HostingEnvironment.ApplicationPhysicalPath, String.Empty)
    .Replace("\\", "/"); 

这篇关于请求是不是在这方面可用 - >在Global.asax中 - >什么是替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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