Get IIS Web Site Application Name

前端 未结 2 2029
一生所求
一生所求 2021-02-20 03:14

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

I can get the IIS server name:

string IISs         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-02-20 03:20

    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
    

提交回复
热议问题