如何使用使用Server.Mappath()从Global.asax中? [英] How can I use Server.MapPath() from global.asax?

查看:266
本文介绍了如何使用使用Server.Mappath()从Global.asax中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用使用Server.Mappath()来的一些文件,我存储在路径相结合的web.config

I need to use Server.MapPath() to combine some files path that I store in the web.config.

不过,由于使用Server.Mappath()依赖于当前HttpContext(我认为),我无法做到这一点。当试图使用的方法,尽管它的可用,我得到了以下异常:

However, since Server.MapPath() relies on the current HttpContext (I think), I am unable to do this. When trying to use the method, even though its "available", I get the following exception:

服务器操作不可用在这方面。

Server operation is not available in this context.

有没有可以充分物理路径映射Web根相对目录,如〜/ App_Data文件/ ç另一种方法:\\的Inetpub \\ wwwroot的\\项目\\ APP_DATA \\

Is there another method that can map a web root relative directory such as ~/App_Data/ to the full physical path such as C:\inetpub\wwwroot\project\App_data\ ?

推荐答案

您可以尝试<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.hosting.hostingenvironment.mappath.aspx\">System.Web.Hosting.HostingEnvironment.MapPath().

无需HttpContext的。

No HttpContext required.

这篇关于如何使用使用Server.Mappath()从Global.asax中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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