How to get “Browse” URL for web site in IIS using C#?

前端 未结 4 1026
渐次进展
渐次进展 2021-01-17 19:38

Say, I have the \"Site Name\" web site in the IIS. I can access most of its functions via the ServerManager class from my C# code. What I can\'t seem to figure out is how to

4条回答
  •  灰色年华
    2021-01-17 20:08

    Right click and go to edit bindings... under Host Name you can actually see which domain it is.

    Or

    Click the site and on actions tab on right hand side you can click bindings...

    To Get the URL :

    HttpContext.Current.Request.Url.AbsoluteUri;
    //http://localhost:8080/app1/Default.aspx
    
    HttpContext.Current.Request.Url.AbsolutePath;
    // /YourSite/app1/Defaul.aspx
    
    HttpContext.Current.Request.Url.Host;
    // localhost:8080
    

    Edit:

    To get site information try using HostingEnvironment.ApplicationHost.GetSiteName() or HostingEnvironment.ApplicationHost.GetSiteID() see below sample(it is not tested) :

    using (ServerManager sm = new ServerManager())
    {
        foreach (Binding b in sm.Sites[HostingEnvironment.ApplicationHost.GetSiteName()].Bindings)
        {
            // ...
        }     
    }
    

提交回复
热议问题