gpt4 book ai didi

c# - 获取 IIS 网站应用程序名称

转载 作者:行者123 更新时间:2023-12-02 23:25:28 33 4
gpt4 key购买 nike

我正在尝试获取我当前所在的 Web 应用程序名称。(我的应用程序代码部署在 IIS 中)。

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

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

当前网站:

string currentWebSiteName = HostingEnvironment.ApplicationHost.GetSiteName();

我找不到获取网络应用程序名称的方法!因为我需要构建一条路径(具体取决于我所在的 Web 应用程序)来获取所有虚拟目录。

最佳答案

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

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

关于c# - 获取 IIS 网站应用程序名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10919295/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com