Get IIS site name from for an ASP.NET website

后端 未结 6 1335
长发绾君心
长发绾君心 2021-02-02 05:59

In my ASP.NET web app I\'d like to look up the name it was given when it was created in IIS, which is unique to the server. I\'d not interested in the domain name for the web si

6条回答
  •  半阙折子戏
    2021-02-02 06:32

    You can use below code

    private string WebsiteName()
    {
        string websiteName = string.Empty;
        string AppPath = string.Empty;
        AppPath = Context.Request.ServerVariables["INSTANCE_META_PATH"];
        AppPath = AppPath.Replace("/LM/", "IIS://localhost/");
        DirectoryEntry root = new DirectoryEntry(AppPath);
        websiteName = (string)root.Properties["ServerComment"].Value;
        return websiteName;
    }
    

提交回复
热议问题