IIS7 rewrite module: change rules without reset an application - iis-7

I use IIS7 rewrite module and all rules are places in a separate config file (not in web.config):
<rewrite>
<rules configSource="Config\Rewrite.config" />
</rewrite>
Is it possible to changes these rules without reset related application?

Related

Outbound URL Redirect Rule to serve content request from an Azure CDN not working

I wrote a redirect rule that will route client's content requests, to the linked Azure CDN serving my hosted ASP.Net MVC website on an Standard plan.
I tried several iteration of the rule; nothing is working
These are the steps I took to implementation
Create Storage
Create CDN ENDPOINT http:// azxxxxxx.vo.msecnd.net/
Created a subdomain at GoDaddy verified and pointing to azxxxxxx.vo.msecnd.net/
Created a public container using Cloudberry Explorer
Uploaded images blobs to the container and
Tested content availability successfully on the browser at http:// azxxxxxx.vo.msecnd.net/images/test.jpeg
Tested content availability successfully on the browser at https:// storage.blob.core.windows.net/images/test.jpeg
inserted the Rewrite-redirect rule on the site web.config file
<rewrite>
<rules>
<rule name="CDN Redirection" stopProcessing="true">
<match url="^images/(.*)" />
<action type="Redirect" url="http:// azxxxxxx.vo.msecnd.net/images/{R:1}" />
</rule>
</rules>
</rewrite>
......( No using the custom subdomain name yet waiting for propagation)
Save, stop and restart website, clear cache, F12, inspect element .....nothing, content still being pulled straight up from the website
So what am I doing wrong?
Check my website at http://www.ehubcap.net
Thank you
This is a simple rule that is tested and works on Azure Websites:
<rule name="images redirection" stopProcessing="false">
<match url="images/(.*)" ignoreCase="true" />
<action type="Redirect" url="https://double.blob.core.windows.net/images/{R:1}" redirectType="Permanent" appendQueryString="true" logRewrittenUrl="true" />
</rule>
Note, you don't need the ^ in your match pattern.
You can check the result here - check the original page source first - IMG element refers to a local image: http://double.azurewebsites.net/images/some.jpg, which is being redirected by the URL Rewrite to the blob storage (you can redirect to any domain you wish).
Note, however, that URL Rewrite module is dependent on other modules. For best results, the UrlRewrite Module should be the first module to process the result. If you have enabled static and/or dynamic compression to compress the output, the URL rewrite will not work. This is because the default configuration kicks the compression module first, then brings the URL Rewrite module. And the URL Rewrite module cannot read compressed content. Yeah, don't ask me why. So, first disable compression (if you have enabled it) to check the URL rewrite config. Then try to reorder the modules. The simplest would be to first remove them, next add the URL Rewrite and then Compression module.

Siteminder root resource rule

I have a ASP.NET MVC Web Site running with Siteminder SOO.
Al security is working correctly, except the Home Page.
In the SiteMinder configuration i have only one Realm with Resource Filter: "/" and Default Resource Protection: "Protected". So, all uris are protected. And i have rules for each uri, and a set of Domain Policies that works fine with these rules. The problem is the root page; i don't know how to write a Rule that allow access to the home page, for example: "http://misite.com/".
If I create a Rule with resource = "/", then the Effective Resource is: "my-siteminder-agent//". And a policy with this rule never applies.
¿How can i create a Rule to allow access to the home page for authenticated users?
I solved it using a Rule on SiteMinder to allow Access to '/Home' and a redirect with the IIS Rewrite Module.
<rewrite>
<rules>
<rule name="Root Hit Redirect" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/Home" />
</rule>
</rules>
</rewrite>
You could also create a unprotected rule to allow the specific home page... ie index.htm
Change the rule to * instead of /*
If the entire site needs to be secured you do not need to create multiple rules for different paths. A standard rule covering everything will be sufficient. Refer to the Answer by #bcarroll to set that up. It will make your life easier when you have to make changes to the policies etc. later.

What is the correct way to be able to serve up an ASP.NET MVC page with URL /areas?

I am trying to get ASP.MVC to handle the URL /areas i.e. http://example.com/areas. By convention there is a folder called Areas, so /areas never gets to my controller.
I want to be able to tell MVC to ignore this folder in this one case.
Ordinarily I would not use a name that conflicts with an existing folder but I am migrating a web application from Django to ASP.NET MVC and have a section of pages under /areas. I would prefer not to have to change all the existing URL's just because of the framework.
For performance reasons I would prefer not to configure all requests to go through the MVC pipeline.
What other solutions are there?
It might be possible to use the IIS URL Rewrite module to redirect requests to specific folder and avoid the MVC pipeline completely.
The example below is from http://learn.iis.net/page.aspx/496/iis-url-rewriting-and-aspnet-routing/ which shows how to rewrite paths to point at a static resource (Under the heading "Static content management.")
<rewrite>
<rules>
<rule name="Rewrite to new folder">
<match url="^Images/(.+)$" />
<action type="Rewrite" url="NewImages/{R:1}" />
</rule>
</rules>
</rewrite>
I'm curious if you could use an IgnoreRoute in your global.asax.cs file which would cause MVC to ignore that completely and not use the MVC processor for anything in that folder
routes.IgnoreRoute("areas/{*pathInfo}");

ASP.net simple rewrite rule

I'm trying to rewrite non www to www domains.
I've tried the rule:
<rewrite url="http://domain\.com(.+)" to="http://www.domain.com$1" />
But to no avail. It just continues to allow access to htttp://domain.com
Most likely you are refering to this one ("Intelligencia URL Rewriter").
As described in their documentation, you have to add the configuration section handler as well as other configuration settings to your web.config file before you can start adding rewrite/redirect rules.
Update
Just saw you modified your question, so probably you managed to find the configuration issue.
For your domain issue, I handled something similar in one of my projects like this:
<!-- Ensure that all are on the same top domain and sub domain. -->
<unless header="HTTP_HOST" match="www.zeta-producer.com">
<redirect
url="^(.*)$"
to="http://www.zeta-producer.com$1"
processing="stop" />
</unless>

IIS7 urlrewrite module - Rules in external xml file

I'm using IIS7 UrlRewrite module.
I set up my rules in the web.config <system.webServer><rewrite> section.
I want to know if there's a way to define the rules in one external xml file instead of in web.config file.
Thanks.
Yes, you can use the configSource attribute to point to an external file like you can with other web.config sections. In the web.config:
<rewrite>
<rules configSource="Rewrite.config" />
</rewrite>
And in the rules config file:
<rules>
<rule name="some rule">
<!-- rule details here --->
</rule>
</rules>
You can still even use the IIS manager to edit rules and it'll just work. One minor caveat with this approach: when you make a change and save an external file like this, it will not recycle the application like making a change to the web.config will. So if you're editing a rule and want to see it take effect, you need to manually poke the web.config by making an edit and saving it.
Another reference: Moving IIS7 url rewrite section out of the web.config file
You can use the sample URL Rewrite providers that include one for storing those in a separate file, see:
http://www.iis.net/learn/extensions/url-rewrite-module/using-custom-rewrite-providers-with-url-rewrite-module

Resources