Get Azure subdomain name after redirect - c#

I am using azure traffic manager which redirects the url to the relevant server based on traffic.
I want to know where it is been redirected or which subdomian
e.g i am hitting https://example.com and traffic manager redirects it to example.cloudapp.net.
In c# code want to get the subdomain or the redirected url
is it possible.any help would be appreciated.

You can specify a cloud Configuration key 'envNAME' = "MyCloudApp1" for first deployment and "MyCloudApp2" for second cloud service deployment. Then you can directly read that config value and as they differ in each of the environments, you can easily identify that where you request has reached by reading that config value.
There could be other easy solutions as well like looking into your request host headers, but I need to try that.
But the above config based solution should work perfectly.

Related

How do I setup reverse proxy in local IIS

I have to implement reverse proxy setup in my local system. I have two website and in first website i have content and second website have empty forlder, I have one website example - www.nawaz-data.com and it has main content. and I have another website example - www.nawaz-proxy.com which is empty folder .
Requirement :
Need how do i setup for reverse proxy. When i request to www.nawaz-proxy.com than it should be redirect to www.nawaz-data.com where i have actual website content. I have tried to setup inbound and outbound rule but unable to get result it shows : HTTP Error 403.14 - Forbidden as this domain has no content, i want to redirect this url to another url where content has stored.
I have installed IIS windows 10
I have installed URL Rewrite
I have installed Application Request Routing Cache - in that I have enable proxy setting
According to your description, I suggest you could try to use below steps to add the reverse proxy rules.
1.Open the IIS mangement console, locate the right web site and click the url rewrite
2.Click the Add rule and select reverse proxy.
3.Add the servername op IP in below window, for example: www.nawaz-data.com. Notice: you should make sure your server could access the "www.nawaz-data.com" directly by using brower. If you couldn't access it ,you should use server's ip address directly.

Need to add a key to allowed origins key in web.config file

I've been looking all through Stackedoverflow and other sites but can't seem to figure out how to do this. I want to add a web address to my web.config allowed origins key. But How do I do this?
I am working on this part of the below web address:
"If you look into Retail Server's log you will see a corresponding error "The >requested resource does not support http method 'OPTIONS". To fix it open Retail >Server's web.config, locate there a key AllowedOrigins and add there the url >corresponding to your dev version of Cloud POS - >https://RetailPosFromSdk.cloudax.dynamics.com if you are following the above >example. Then save the file and click Retry in Cloud POS. Now you should be able >to select the Store, Register and Device - basically the same experience when >you use Prod version of your Cloud POS."
https://community.dynamics.com/ax/b/axforretail/archive/2016/06/25/how-to-run-cloud-pos-from-retail-sdk

301 Redirection of website URL

currently we have our website running like this: websitename.com. But we've added multiple languages to it so now all the English content will be available at websitename.com/en and the Russian content will be available at websitename.com/ru. Google has already indexed the URLs at websitename.com. Now, I want to redirect these URLs to default en.
i.e. websitename.com/page1 to websitename.com/en/page1
How do I acheive this?
Redirection is one way to make sure that users always receive the Web
page that they want. Redirection refers to the process of configuring
the Web server to issue a redirect message to the client, such as HTTP
302, which instructs the client to resubmit the request for a new
location. You can redirect users to another file, directory, or site.
You can check MSDN article about IIS Redicrection. Check the links in Procedures section.

Wrong host returned using HttpContext.Current.Request.Url.Host

We have multiple domains for one of our websites.
e.g. mydomain-uk.com and mydomain.co.uk
I have a handler which creates an XML sitemap and it uses HttpContext.Current.Request.Url.Host to retrieve the host site.
When my browser is on mydomain.co.uk/handler it retrieves mydomain-uk.com as the host
How can I ensure it always retrieves mydomain.co.uk ?
Is there a preference order configured somewhere on the server?
The host is get it from the URL on the request, and this is logical, you can not change this.
To solve this, create a static variable with your URL name, even better place it on your web.config, and just get this variable and not the Url.Host
Hope this help
Don't point all of your domains at the website. Have the extra domains perform a 301 redirect to the main domain name. This will also help resolve confusion by search engines when they try to resolve your site as to which site is the original source of your content, and will prevent inbound links from other websites from using a mixture of domains which will only exacerbate the problem.
Don't forget that HttpContext.Current.Request.Url.Host is simply going to return whatever HOST was requested at the time it happened. If the client requested something else, HttpContext.Current.Request will reflect this.

SPItemEventReceiver Context SiteId/WebUrl Incorrect

I have created a SharePoint Event Receiver, that fires on Item Update.
The receiver needs access AfterProperties and ListItem.
When firing the event receiver from a SharePoint web application using an IP address (http://10.0.4.50/sites/), it throws a FileNotFoundException, when accessing SiteId And WebUrl in SPItemEventProperties.
The Web application at http://10.0.4.50/sites/companyName could not be found. Verify that you have typed the URL correctly.
When firing the event receiver using the hostname, specified at setup of Site Collection http://computerhostname/sites/companyName. This works fine, no exception is thrown.
//Combine Both AfterProperties And ListItem
var ListProperties = new List<KeyValuePair<string, object>>();
ListProperties.AddRange(properties.AfterProperties.ToKeyValue());
ListProperties.AddRange(properties.ListItem.ToKeyValue(p => !p.Sealed));
var AvaliableProperties = ListProperties.Distinct(new KeyValueComparer<object>());
This isn't necessarily a SharePoint problem, but is most likely down to the way that IIS is configured on the host. A particular site can be "bound" to an IP address and a host name, and if the host name isn't present in the HTTP GET sent by the browser then IIS will return a 404 NOT FOUND.
You can verify this by using a browser to see whether you can access the site by IP address.
You can add additional bindings if necessary, but there can only be one "default" binding per IP address, so only one site can be present at (in your case) 10.0.4.50.
A possible way around the situation where multiple sites are present but you can't use a hostname might be to add a binding to a port other than port 80 for this IP, so your URL would become something like http://10.0.4.50:8080/sites/companyName.
This is not just an IIS problem, but Sharepoint related as well. A lot of referencing in SharePoint is done by using a url as a starting point (just look at the constructor of SPSite). The url is then compared to known url's in SharePoint's Config database. (and ofr files etc in the site's content database).
SharePoint uses a system called Alternate Access Mappings to assign different urls to a Web Application's "Zones" (default, intranet, internet, ... custom definition). If it does not find the 'exact' Url, internally stuff will fail (And especially search is very "Url sensitive").
Then comes the IIS part into play: Since IIS probably has no other site running on the 80 port, and without a specific hostheader (so it defaults to machinename), or with the hostheader set to the machine name, IIS will pick up the request and since SharePoint is tied into this webapp, SharePoint will try to process it, looks up the url, Sharepoint does not find the Url and thne "breaks".
The no hostheader occurs when you leave the hostheader field empty when you create a new web app in SharePoint.

Categories

Resources