c# - Programmatically retrieve the site URL from inside an Azure website -


Azure websites have "site URL" provided by Ezur, such as mysite.azurewebsites.net. Is it possible to get from within (i.e. ASP.NET applications)?

There are several properties in the environment and the HTTPRTime class, which have the name of the website (like "MySite") so that it is easily accessible. Things are getting complicated when not by default, but eg The site's staging slot is accessed (including sites such as MySite-Steiging.JourWebsites).

So I was just wondering if this site is a direct way of getting the URL directly, if not, by using any alleged class to get the name of the site and then the site slot address

> Edit (2/4/16): You can get the URL from the app settings / Ryavarnwartniy Vebsaitup .

If you have a setup, this will also give you a custom hostname.

There are some ways you can do that.

1. By HOSTNAME . Header

This is valid only if the request & lt; SiteName & gt; is killing the site using .azurewebsites.net . After that you can just type heading for HOSTNAME > siteName & gt; .zurewebsites.net

  var hostname = request. Header ["HOSTNAME"]. ToString ()   

2 WEBSITE_SITE_NAME from the Environment variable

This is just for you & lt; SiteName & gt; divides, so you have to attach the . Zurewebsites.net part

  var hostName = string.Format ("http: // {0} .azurewebsites.net", environment. Expand Environment Environment ("% WEBSITE_SITE_NAME%" ));  MWA   

using bindingInformation to applicationHost.config using

Code, and then binding notification your property on your site may look slightly different, something like
  private static string GetBindings () {// Site Name String SiteName = System Web. Hosting Hosting Enterprise.SiteName; // Find the sites section from AppPool.config Microsoft.Web.Administration.ConfigurationSiteSites = Microsoft.Web.Administration.WebConfigurationManager.GetSection (empty, blank, "system.applicationHost / sites"); Analysis site in foreach (Microsoft.Web.Administration.ConfigurationSiteSetting.GetCollection ()) (if true) site string (excel (string) site ["name"], sitemap, string compiler, ORDINAL Ignore case) // For restrictions, see if they are http based and port and protocol leading (Microsoft.Web.Administration.ConfigurationElement binding site.GetCollection ("binding")) {var bindingInfo = (string) binding ["binding information"]; Binding Information Index (".zquo; azurewebsites.net", String Communications. Inverarity Culture Igniter Sees) -1) {Return Binding Info Split (':') [2];}}} Return Null;}   

Personally, Will use

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -