How to configure web.config to load resources form external server - visual-studio

I'm developing a web application in Visual Studio 2013 and am getting my data from an external server. For this reason I disable the web securtiy in my browser and define absolute URLs in my application. Now whenever I'm deploying the applicaiton, I have to adopt the URLs (which of course get's forgotten the first time) and also I have to explain the setup to evey person new in the porject.
After getting a bit fimilar with the web.config file, I tried to setup some rules, to rewirte this urls to the data webserver, but failed.
All my relative urls start with the same identifyer, and should be mapped to an external server. This is what I have so far:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite calls to rest.oms to the actuall webserver">
<match url="^/IDENTFIER/([_0-9a-z-]+)" />
<action type="Rewrite" url="http://EXTERNAL_SERVER/IDENTFIER/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
However, it is not working so far. Can somebody help me please.
Best Regards,
Stefan

It is possible to rewrite from external url, if you have ARR module.
1) You need to install ARR module for your IIS
2) In IIS manager you should enable reverse proxy
2.1) On server node click "Application Request Routing Cache"
2.2) Click "Server proxy settings" and click "Enable proxy", then "Apply"
3) Slightly fix your rewrite rule regexp (remove starting slash):
<rule name="Rewrite calls to rest.oms to the actuall webserver">
<match url="^IDENTFIER/([_0-9a-z-]+)" />
<action type="Rewrite" url="http://EXTERNAL_SERVER/IDENTFIER/{R:1}" />
</rule>
Then your rule should work.

Related

keep URL same and load content of different website

I have first.abc.com/xyz (xyz being an application under main domain abc.com) that needs to load content off of a different website second.abc.com/whatever/xyz while keeping the URL same to first.abc.com/xyz how is this possible? I have looked into a couple videos for reverseproxy with ARR, but I am not an expert on servers. Hope I am clear on the issue at hand. Any help would be great.
you need to install
IIS URL rewrite module
IIS ARR routing for reverse proxy using
then add the routing in web.config ,or add in the applicationhost.config
here is the example
<rule name="ReverseProxy" enabled="true" stopProcessing="true">
<match url="(xyz)$" />
<action type="Rewrite" url="http://first.abc.com/xyz" appendQueryString="false" logRewrittenUrl="true" />
</rule>

URL rewriting - Rule seems ok but completely ignored IIS 7

I want to redirect request going to "oldSubDomain" to "newSubDomain".
Here what the URL looks like :
https://oldSubDomain.myWebSite.com
should go to
https//newSubDomain.myWebSite.com
Here the rule as it has been added to the web.config :
<system.webServer>
<rewrite>
<rules>
<rule name="NewSubDomain">
<match url=".*oldSubDomain.*" />
<action type="Redirect" url="https://newSubDomain.myWebSite.com/" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Rule seems OK, but when I go to "https://oldSubDomain.myWebSite.com", the rule seems being ignored and I get the oldsubdomain pages...
I am using IIS7.0 and the web application is done using MVC 4.5.
An idea ? Anyone ?
Many thanks.
See this answer. Basically it appears that the only portion you will be given is the portion relative to your web.config file. It is possible that if you have the web.config defined in the mywebsite.com directory that you are only getting the myWebSite.com portion for matching.

Azure website as a caching reverse proxy using ARR

We are migrating one of our websites to Azure which was previously setup using ARR (Application Request Routing) as a caching reverse proxy. It was setup as a reverse proxy which would honor the cache headers of the site it was proxying.
I've followed this guide on using an Azure website as a reverse proxy and it all works fine except that it doesn't honor the cache headers of the site it is proxying. I tried adding some more pertinent elements to my applicationHost.xdt, but nothing I do seems to have any effect.
Here is the relevant section from my applicationHost.xdt:
<system.webServer>
<caching xdt:Transform="Replace" enabled="true" enableKernelCache="true" maxResponseSize="1000000"></caching>
<proxy xdt:Transform="InsertIfMissing" enabled="true" reverseRewriteHostInResponseHeaders="true" minResponseBuffer="4096" responseBufferLimit="12392">
<cache enabled="true" queryStringHandling="Accept" validationInterval="00:01:00" />
</proxy>
</system.webServer>
and here is my web.config:
<system.webServer>
<rewrite>
<rules>
<rule name="CurrentTime" stopProcessing="true">
<match url="^times/?(.*)" />
<action type="Rewrite" url="http://example.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
The web.config just routes all requests to /times to example.com. That part is working great. It is just ignoring the cache headers of example.com and not caching anything which is the main use case of why we want to setup a reverse proxy.
This same configuration works just fine on a normal machine with IIS and ARR installed.
I'd really like to get this working in azure websites without having to use a web role in a cloud service. I'm hoping this is possible.
Did you try to specify the preserveHostHeader="true" flag as follows?
<proxy xdt:Transform="InsertIfMissing" enabled="true" preserveHostHeader="true" reverseRewriteHostInResponseHeaders="true" />

IIS Url rewrites with Sitecore

I'm using the IIS URL rewrite add-on in my Sitecore v7.2 website to handle redirects.
I've setup the Rewrites on the website node in IIS and not on the top level IIS server.
These are simple redirects such as appending a slash in certain situations
<rule name="CA Redirect" stopProcessing="true">
<match url="^ca$" />
<action type="Rewrite" url="{R:0}/" />
</rule>
I'm finding that unless I add the path e.g. "/ca" to the IgnoreUrlPrefixes in Sitecore IIS will not process the redirect, and it appears that Sitecore is handling the request before the URL rewrite rule.
Has anyone else come across this issue? Should the rules be added at the top level rather than the website level?
We're using redirects at website level and it works without problems. IIS is redirecting before Sitecore handles the request.
Doing it at site level is generating this in the web.config
<rewrite>
<rules>
<rule name="Web closed" enabled="true" stopProcessing="true" patternSyntax="Wildcard">
<match url="*" />
<action type="Rewrite" url="/holdingpage.html" logRewrittenUrl="true" redirectType="Temporary" />
</rule>
</rules>
</rewrite>

How do you properly install an ASP.NET MVC app as a child of another MVC app?

I have a main website app written in ASP.NET's MVC 3. Now, what I would like to do on occasion, is add a subdirectory, mark it as an application and run a whole different MVC 3 app from that directory. For instance, my site is at http://sol3.net. I am working on a small MVC app for a client and I'd like to publish it on my site so he can take a look at the progress, offer feedback, etc. So, their site would be at http://sol3.net/projectA. Having done this with a test app all I am getting is a 500 error.
Are there any best practices on how to set this up?
And yes, I already know about web.config inheritance problems. Fortunately my web.configs are not too large and I think I have most everything handled there.
NOTE: What I am trying to do is temporarily run a MVC app (App B) from within an app folder on an already active site (App A). App A and App B do not share anything in common and App B will eventually be moved to its own hosting site.
NOTE #2: The Answer...
I believe it is IIS7 and higher that allows you to add a redirection in your root web.config. Here is what I ended up doing instead of doing it via IIS Manager:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<rewrite>
<rules>
<rule name="APP 1 - Sub domain to sub folder" enabled="true">
<match url="(.*)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(www\.)?app1\.sol3\.net$" ignoreCase="true" />
</conditions>
<action type="Rewrite" url="app1/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
You would add a subdomain via an alias in your DNS records. Some registrars will let you do this yourself, but some sell this as a feature. A whois on your domain says it's registered with GoDaddy. Check this out. http://help.godaddy.com/article/4652#addsubdomain1
Edit - OrcsWeb allows for remote management of your web site via IIS 7 Manager. This should allow you to edit the host header. http://www.orcsweb.com/blog/brad/iis-7-manager-for-remote-administration-installing-and-connecting-to-a-site/

Resources