app_offline.htm not working for rewritten URLs - asp.net

I have a Rewrite rule for a specific page, to make it more SEO friendly.
<rewrite>
<rules>
<rule name="Friendly Threads">
<match url="Topic/([^/]*)/([^/]*)/[^[#\?]*\??(.*)" />
<action type="Rewrite" url="thread_messages.asp?ThreadID={R:1}&PageNumber={R:2}&{R:3}" />
</rule>
</rules>
</rewrite>
But whenever I drop an app_offline.htm file in the root, the site will go to the app_offline.htm page for all URLs except for those matching the above match.
Is this expected, or have I possibly got something misconfigured somewhere?
If it makes any difference, this is a classic ASP site running under IIS 8 (Windows 2012).
(And yes, I know this is like putting a 90 year old behind the wheel of a Lamborghini.)

As far as I know app_offline.htm only works for ASP.NET. As the rewrite result is classic ASP, the page is handled by another IIS module, so it won't care about app_offline.htm existence.
In another saying, you have done nothing wrong, but classic ASP does not support app_offline.htm.

Related

Coldfusion to .NET pages .cfm to .aspx in Web.Config

Creating redirects for Coldfusion pages to .Net pages through web.config. Looking for guidance on handling .cfm request and converting them to .aspx on a windows server with IIS 7.5. Ideally 301 redirects for SEO purposes.
Anyone know an efficient way to handle .cfm request and convert them to .aspx through web.config?
I work with Coldfusion 9.x.x on IIS 7.5 and 8 and here is what we do.
Say you have a link that appears like this:
http://example.com/index.cfm?articleid=12&displayText=title-of-the-article
You'll need this basic structure added to your web.config file:
<rewrite>
<rules>
<rule name="Article Stripper" stopProcessing="true">
<match url="^([\w-_+]+)/([\w-_+]+)" ignoreCase="false" />
<action type="Rewrite" url="/index.cfm?articleid={R:1}&displayText={R:2}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
To produce something like this:
http://example.com/12/title-of-the-article
You can do using Application_BeginRequest() event in Global.asax.
Please check out following link for further details on it.
Asp.net processing of .CFM files or Redirects from .cfm to .aspx page

ASP.NET HttpContext.RemapHandler to remap to ASP Classic

We are upgrading an ASP Classic website (actually, a virtual directory under a larger website) to ASP.NET 3.5. There will be some legacy directories that remain ASP Classic. Other than that, every .asp file will be replaced by an .aspx file in the same location in the directory hierarchy. We would like not to break old links coming into the site from elsewhere. The website is hosted on IIS 6 (and we have no control over this).
My idea was, in IIS, to replace the usual handler for .asp files, asp.dll, with aspnet_isapi.dll. First question: If I do that, will requests for .asp files then be routed through any custom HTTP modules I create and register in web.config?
Then I would create an HTTP module hooked into BeginRequest that would test whether a request's path (before any querystring) ends in .asp. If so, it would check whether the physical file exists. If not, then I'll use HttpContext.RewritePath to append the "x" to the ".asp". Otherwise, if the .asp file DOES exist, I'll use HttpContext.RemapHandler to switch the handler back to asp.dll so that the file will be processed as the ASP Classic file that it is.
Second question: Will this work? Third question: What do I use as the argument to the RemapHandler method? How do I acquire a reference to an instance of the ASP Classic handler? (If I knew the answer to the third question, I'd have just tried all this on my own!)
UPDATE: OK, I did try it out myself, except that I renamed the remaining .asp files so that their extension is .aspc (ASP Classic), and in IIS I assigned the old asp.dll as their handler. Then, instead of checking whether the .asp file requested exists and remapping to the ASP Classic handler if so, I checked instead whether a file in the corresponding physical location except with the extension .aspc exists. If so, I rewrite the URL to append the "c". This worked! Therefore, the answer to my first question, above, is "yes", and the answer to my second question is "yes, pretty much, except that the part about remapping the handler is unknown". But it would be preferable not to have to change the extensions on all my legacy .asp files, so I am left with one question: Will the original RemapHandler approach work and, if so, what is its argument?
Did you know, that you could handle this quite easily using the web.config file and redirect rules in IIS?
You need to activate the URL Rewrite2 module described here.
This is a really nice feature of IIS, to solve routing problems, see here also for some examples.
Looking at your case, I would do something along the lines of this:
<rule name="execute classic asp if file exists" stopProcessing="true">
<match url="(\w+\.asp)$" />
<conditions>
<add input="C:\Path\To\Your\WebApp\{R:1}.asp" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:1}c" appendQueryString="true" />
</rule>
<rule name="execute dotnet otherwise" stopProcessing="true">
<match url="(\w+\.asp)$" />
<action type="Rewrite" url="{R:1}x" appendQueryString="true" />
</rule>
I'm not sure if all RegExes here would work for you, but its meant as a start to experiment. The reason to explicitely write C:\Path\To\Your\WebApp\ is, that I didn't find a way to get the base path of the web app as a parameter.

IIS 7 URL Redirect based on URL path

I have a WCF Web Service hosted inside a ASP.NET 4 environment (IIS 7.5 on Windows 7), and I would like to use URL Rewriting / Redirection.
The reason I need to do this is because I can't change some mobile device code to just insert the parameter.
Here is the URL I want:
http://server.test.com/VirtualDirectory/theOrganization/RequestService.svc/REST/GetIssueTypes
The real URL is:
http://server.test.com/VirtualDirectory/RequestService.svc/REST/GetIssueTypes?organization=theOrganization
Notice how I want to remove theOrganization and appended it to the Query string for redirection.
<rule name="test" stopProcessing="true">
<match url="(.+\.?)/(.+)/RequestService.svc/(.+)" />
<action type="Redirect" url="{R:1}/RequestService.svc/{R:3}?organization={R:2}"
redirectType="Permanent" />
</rule>
I know it's a little odd of a rule to write. Thinks i have my regular expression correct for matching. I run the expression in the URL Rewrite tester in IIS Manager, and it seems like it's matching what I want. Also, I do have IIS URL Rewrite installed, and I made a simple rule up and it worked.
However, when I try it using a browser, it failed to redirect and results in a 404. I was hoping a IIS Rewrite expert could chime in, as I am fairly new at it.
Thanks!
I tested your rule on a test server with iis 7.5 and url rewrite 2.0 and the rule is working, but your regex matches both your wanted url and the real url.
So you end up with a double redirect
I think you want your pattern something like this
(.+.?)/VirtualDirectory/(.+)/RequestService.svc/(.+)
Hope this helps.

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}");

extensionless url in IIS7.5

I have a website, which is been working on Dotnetnuke. I am using dotnetnuke's friendly url to use clean url's instead of asp's ugly QueryString urls, now my problem is, what configuration does it need for the extensionless urls in dotnetnuke using IIS7.5, i checked lots of websites on google, but could not make it, how can i use extensionless urls in asp.net, as Dotnetnuke just allows friendly urls and not extensionless urls.
I even tried using URLRewriter.net, but that too didnt helped.
How can I use extensionless url in asp.net?
I thought your website in 4.0 framework right??
go to iis and site application pool set to classic instead of integrated (Managed pipeline mode:).
then go to your site in IIS and open "Handler Mapping" section and add a "Wildcard Script Map..." Request path = * and Executables = 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" loaproper location of this file and then restart your IIS and run your site.
I hope it will helps you....
I recommend using IIS URL Rewriter with the following rule:
<rewrite>
<rules>
<rule name="Rewrite Tab" stopProcessing="true">
<match url="^([a-z0-9/]+)/tabid/([0-9]+)/([a-z0-9/]+)$" ignoreCase="true"/>
<action type="Rewrite" url="default.aspx?tabid={R:1}"/>
</rule>
</rules>
</rewrite>
This will rewrite
/Category/Subcategory/tabid/123/Default
to
/default.aspx?tabid=123
You might also be able to modify DNN's internal rewrite engine rules.
Have you looked into IIS 7's built in URL rewriter?
http://learn.iis.net/page.aspx/461/creating-rewrite-rules-for-the-url-rewrite-module/

Resources