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 If you have a setup, this will also give you a custom hostname. There are some ways you can do that. This is valid only if the request This is just for you using Personally, Will use URL from the app settings / Ryavarnwartniy
Vebsaitup .
1. By
HOSTNAME . Header
& 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
& 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
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;}
Comments
Post a Comment