获取IIS网站应用程序名称 [英] Get IIS Web Site Application Name

查看:298
本文介绍了获取IIS网站应用程序名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取当前使用的Web应用程序名称.(将我的应用程序代码部署在IIS中的位置).

I'm trying to get the web application name I'm currently in. (Where my application code is deployed in IIS).

我可以获取IIS服务器名称:

I can get the IIS server name:

string IISserverName = HttpContext.Current.Request.ServerVariables["SERVER_NAME"];

当前网站:

string currentWebSiteName = HostingEnvironment.ApplicationHost.GetSiteName();

我找不到获取Web应用程序名称的方法!因为我需要根据我使用的Web应用程序来构建路径,以获取所有虚拟目录.

I can't find a way to get the web application name! Because I need to build a path, depending in what web application am I, to get all virtual directories.

推荐答案

10月23日的答案仅遍历所有应用程序.问题是如何从IIS上运行的应用程序获取当前的应用程序名称.具有讽刺意味的是,上面的问题帮助我回答了这个问题.

The Oct 23 answer only iterates through all the apps. The question was how to obtain the CURRENT application name from an application running on IIS. Ironically, the question above helped me answer it.

using Microsoft.Web.Administration;
using System.Web.Hosting;

ServerManager mgr = new ServerManager();
string SiteName = HostingEnvironment.ApplicationHost.GetSiteName();
Site currentSite = mgr.Sites[SiteName];

//The following obtains the application name and application object
//The application alias is just the application name with the "/" in front

string ApplicationAlias = HostingEnvironment.ApplicationVirtualPath;
string ApplicationName = ApplicationAlias.Substring(1);
Application app = currentSite.Applications[ApplicationAlias];

//And if you need the app pool name, just use app.ApplicationPoolName

这篇关于获取IIS网站应用程序名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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