你如何确定没有的HttpContext文件的物理路径? [英] How do you determine the physical path of a file without an HttpContext?

查看:171
本文介绍了你如何确定没有的HttpContext文件的物理路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有没有在ASP.NET MVC Web应用程序的运行HttpContext的一些过程。这个过程需要能够确定到读取/写入数据的应用程序的内容目录的物理路径。但是,既然是没有一个HttpContext的,我没有得到使用像和使用Server.Mappath等花哨的东西。建议?

I have some processes that run without an HttpContext in an ASP.NET MVC web application. This process needs to be able to determine the physical path to the Contents directory of the application for reading/writing data. But, since it is without an HttpContext, I don't get to use fancy things like Server.MapPath and such. Suggestions?

推荐答案

在一个网站时,最好使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.httpruntime.appdomainapppath.aspx\"><$c$c>HttpRuntime.AppDomainAppPath,因为在执行路径的某些时刻(即当网站启动时),有没有 HttpContext.Current 可用。

In a website, it is best to use HttpRuntime.AppDomainAppPath, because in certain moments of the execution path (i.e. when the site starts up), there's no HttpContext.Current available.

又见<一个href=\"http://stackoverflow.com/questions/3025984/how-to-get-the-physical-location-of-an-asp-net-web-application-without-using-http\">this帖子。

这篇关于你如何确定没有的HttpContext文件的物理路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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