如何从.cs文件获取虚拟目录别名 [英] how can I get the virtual directory alias name from .cs file

查看:70
本文介绍了如何从.cs文件获取虚拟目录别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



谁能告诉我如何从C#代码获取IIS中托管的网站的虚拟目录别名?

在此先谢谢您.

Hi,

Can anyone tell me how can I get the virtual directory alias name of the website that is hosted in IIS from C# code?

Thanks in advance.

推荐答案

不确定您在说什么,但是您始终可以获取当前页面/资源的完整路径(绝对路径)在代码中使用.路径中将包含所有内容-虚拟目录名称,资源相对路径等.提取所需的内容.
Not sure of what exactly you are talking of but you can always get the full path (absolute path) of the current page/resource you are using in the code. You will have all the things in the path - virtual directory name, resource relative path, etc. Extract the one you need.


好吧,我检查了上面的讨论.

使用此
Okay, I checked your discussion above.

Use this,
Request.ServerVariables["PATH_INFO"];



这会给您:/别名/...

提取别名.

希望对您有所帮助!



this will give you: /alias/...

Extract the alias.

Hope this helps!


尝试以下操作:

字符串vDirectory =";
如果(Request.ServerVariables ["APPL_MD_PATH"]!=")
if(Request.ServerVariables ["APPL_MD_PATH"].Remove(0,Request.ServerVariables ["APPL_MD_PATH"].IndexOf("ROOT/")+ 5)!=")
vDirectory = Request.ServerVariables ["APPL_MD_PATH"].Remove(0,Request.ServerVariables ["APPL_MD_PATH"].IndexOf("ROOT/")+ 5)+"/";
try this one:

string vDirectory = "";
if (Request.ServerVariables["APPL_MD_PATH"]!="")
if (Request.ServerVariables["APPL_MD_PATH"].Remove(0, Request.ServerVariables["APPL_MD_PATH"].IndexOf("ROOT/") + 5) != "")
vDirectory = Request.ServerVariables["APPL_MD_PATH"].Remove(0, Request.ServerVariables["APPL_MD_PATH"].IndexOf("ROOT/") + 5) + "/";


这篇关于如何从.cs文件获取虚拟目录别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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