ASP.NET获取URL从物理文件路径 [英] ASP.NET Get physical filepath from URL

查看:584
本文介绍了ASP.NET获取URL从物理文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从一个ASP.NET的URL获得物理文件路径?

Is there a way to get the physical filepath from an ASP.NET's URL?

之情况:我有一个应用程序,是在两个西弗斯,但现在会在其它更多,而且每个服务器都会在一个不同的物理文件路径。现在我这样做:

Scenerio: I have an app that is on two severs, but it will now be on lots more, and each server puts it in a different physical file path. Right now I'm doing this:

//for server 1
if (Request.Url.GetLeftPart(UriPartial.Path).Contains(".com"))
 { Application["StoreFilesPath"] = "E:\\Data\\rootsite\\f1\\appsite\\Upload\\"; }

//for server 2
if (Request.Url.GetLeftPart(UriPartial.Path).Contains(".net"))
 { Application["StoreFilesPath"] = "E:\\Web\\rootsite2\\f34\\abc\\ghi\\appsite\\Upload\\"; }

但我需要做的是这样的:

But what I need to do is something like this:

//for all servers
Application["StoreFilesPath"] = getPhysicalFilePath() +"\\Upload\\";

我该怎么办呢?

推荐答案

您可以使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx\"><$c$c>HttpServerUtility.MapPath就为了得到一个文件的物理路径,然后在应用程序返回它会话对象的服务器端,同样以你现在正在做什么。

You can use HttpServerUtility.MapPath on the server side in order to get the physical path of a file, then return it in the Application or Session object, similarly to what you are doing now.

作为URL的物理路径 - 可能没有一个,因为网址可重写

As for the physical path of a URL - there might not be one, as URLs can be re-written.

这篇关于ASP.NET获取URL从物理文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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