ASP.NET - IIS Custom Mapping Extensions - How? - asp.net

I am wondering how one goes about creating/rerouting my custom developed .ASPX pages on IIS 6.0 pages to something totally custom w/o the .aspx extension, say, .vato? For example, instead of my page saying: Default.aspx?ID=123, I would like users to see: Default.vato?ID=123.
What concept is? Is this doable? Where can I research more on this topic?

Yeah, read this:
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/4c840252-fab7-427e-a197-7facb6649106.mspx?mfr=true
Create a new entry for your new extension and map it to the same executable as the .aspx handler.
The common one is to add a wildcard. This allows you to have URLs without extensions at all. IMO, that's much preferred because extensions make little sense on the internet.

It's not so much a .net question as it is an IIS question.
Basically, IIS looks at what extension is being requested and responds accordingly.
There is a list of all file extensions and what actions should be taken when these are requested. In terms of .net, these are .aspx, .ascx, asmx, etc. These are basically ISAPI filters.
Depending on your version of IIS. If you open IIS Manager, choose the website in question, go to Properties, then Home Directory, then Configuration, under Mappings you will see all file extensions and the application that will be called to action this request.
Therefore, if you add an entry for .vato, and point it to your version of .net, such as C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll then the .vato file will then be treated the same as a .aspx files.

In IIS (6.0) click on "Configuration" on your Web Site page and you can add mappings there. It must reference the same ASP.NET ISAPI DLL as for example the ASPX pages.
You can also add * and have all requests route to a HTTP module but that's a little more advanced and useful for the likes of REST.

Related

Help in locating the URL rewrites in place for an asp.net website

First off i'll advise i'm not familiar with implementing url re writing on any level.
That said I do know there are 2 types or rewrites setup for this site.
One I can locate and is solely responsible for top level rewrites (turning .com to .co.uk)
There is another rewriter implemented somehow somewhere, very early on in a pages lifecycle and I cannot find how or where the site is doing this. It's possible it's all handled in a 3rd party DLL but I would like to know the steps I might go through to prove or disprove this.
Thanks
What does your web.config have registered in the httpModules section? Often URL Rewriters are registered very early in the request life cycle. httpModules and httpHandlers can grab the request here. This is of course assuming you've ruled out IIS redirects. After that you can look for manual redirection in the global.asax file. There are a lot of places to look when you don't know how the original coder decided to implement the idea. I've seen some bad places, including in the constructor of a common base page inherited by every page on the site.
URL rewriters are typically ISAPI filters - you can search currently applicable ISAPI filters on Web Site or Folder properties in IIS 6 (you might have ISAPI filters in right context menu), on II7, ISAPI filters in features view when you select web site or folder.
With .NET 3.5 or 4.0, its possible that ASP.NET routing might be the reason - you can locate that in web.config or global.asax (common places for putting the routes).
My word i'm so sorry after finally tracking down an original dev there is no re-writes whatsoever. The solution is complex but workable. Weird etc :). Love IT.

ASP.NET ascx.cs via GET

Say I have this url:
http://site.example/dir/
In this folder I have these files: test.ascx.cs and test.ascx
Just to be clear, I am not a .NET developer.
From a security point of view - why can't I access http://site.example/dir/test.ascx.cs and how secure is it to keep those files there?
I assume IIS filters out request that query these kind of files, but can someone explain me this?
Thank you.
You just explained it yourself. IIS won't serve those files.
When you register ASP.NET with IIS (aspnet_regiis.exe) it will add common extensions and associate them with the ASP.NET handler. As far as the .cs extension is concerned it is filtered and not served by IIS. It is absolutely safe to have these files there, but I would recommend you to use an ASP.NET application project (in contrast to ASP.NET website) which is precompiled and you don't need to deploy source code files on your server.
(source: wewill.cn)

Application_BeginRequest for static *.JS files in ASP.NET in IIS6?

I'm trying to do something seemingly simple: ensure that Application_BeginRequest is called for every static *.JS URL sent to my IIS6 website, whether or not the underlying file exists.
What's a good way to do this on IIS6 & ASP.NET 3.5, ideally without causing all static files to go through ASP.NET-- only the .JS URLs?
If you're curious about why, I'm working with an existing app that uses Application_BeginRequest to do custom redirection and path rewriting. It woudln't have been my first choice to implement it this way, but given what's there I want to extend it to cover .JS too, instead of including another different redirection/rewrite method (e.g. IIS redirection configuration, a rewrite module, etc.) which may complicate deployments and testing of the app, especially on IIS6.
I know the IIS7 story here is much, much better (esp. around XCOPY deployment of configuration, modules, etc.), but I can't upgrade this app right now.
I haven't tested this, but in IIS Manager, on the properties of your site click the Home Directory tab, and click configuration - add a .js extension that maps to aspnet_isapi. Make sure you uncheck the "Verify file exists" checkbox. You might need to play around with the other options.

ASP.NET URL rewriting for DB query from URL content without extension

I am trying to create a very simple ASP.NET application that presents information retrieved from a database based on the URL, in a similar way to a wiki, but in this case the site is read-only. An example of a URL I'd like would be:
http://www.foo.com/bar
The application would then use "bar" as a SQL query parameter to show information from the database that matches "bar".
I've looked into many URL re-writer options for IIS6 (and this would be on a dedicated server), but I'm still not sure which one to use for this application.
To perhaps clarify, I only need to run the site from a single default.aspx file, but I want it to work as described above. The overall site logic will be very simple.
I am hoping that someone with more experience in this area can help me out -- I am looking for the simplest solution that will address this one scenario.
IIS6 only directs requests to the asp.net engine if that extension has been registered. By default the registered extensions are aspx ascx asmx etc...
If you cannot base you database query on a query string parameter (e.g. foo.com/default.aspx?query=bar) then the best you can do on IIS6 is a wildcard mapping. Basically this means that every request will be directed over to asp.net (including images scripts and styles.) obviously this will degrade performance.
To enable wildcard mapping right click on your site in IIS manager and go to Properties -> Home Directory -> Configuration -> Mappings at the bottom click insert and type in the path to the asp.net isapi dll (you can copy it from the aspx extension above) and uncheck 'Verify that file exists'.
After making the changes you'll be able to request foo.com/bar
(another method might be to make a request to foo.com/default.aspx/bar)
Just for the record, IIS URL Rewrite 2 supports this, you can install the extensibility samples that include a DB provider. Works on IIS 7+ only.
http://www.iis.net/download/urlrewrite
http://code.msdn.microsoft.com/rewriteextensibility

ASP.NET/IIS: 404 for all file types

I set up 404 handler page in web.config, but it works ONLY when extension of URL is .aspx (or other which is handled by ASP.NET).
I know I can setup static HTML page in website options, but I want to have a page.
Is there any options to assign ASPX handler page for all request extensions in IIS?
The direct question was whether or not there are options to assign the ASPX handler to all request extensions: Yes, there is. I'll discuss how to do that shortly.
First, I think the "hidden" question -- the answer you really want -- is whether or not there's a way to redirect all 404 errors for pages other than ASPX, ASMX, etc. Yes, there is, and this is the better choice if it'll solve the issue you're having.
To redirect all 404s in IIS 6, right click your web application root (whether it be its own site or a virtual directory in the main site), and choose "Properties." From there, choose the "Custom Errors" tab. Find 404 in the list and change it to the redirect you want.
Now, if that won't suffice -- and I really hope it does -- yes, you can run every page through the ASPX handler. However, doing so comes at a fairly high cost in terms of efficiency -- raw HTML/image serving is considerably faster than anything dynamic.
To do this, right click your web application root and choose "Properties." Choose the "Home Directory" tab. Click "Configuration;" a new window will pop up. Copy the path from one of the ASP.NET page serves, and then use it for a wildcard application map.
Bear in mind, again, this is the wrong answer most of the time. It will negatively impact your performance, and is the equivalent of using a chainsaw to carve a turkey. I highly recommend the first option over this one, if it will work out for you.
For information:
This is one of the several nice things that IIS7 brings - all pages are routed through the handler such that you can do custom 404s and - usefully - directory and file level security for any file (based on the same web.config stuff as for asp.net files prior to IIS7).
So notionally "use II7" is an answer (will be "the" answer in time) - but of course its not a terribly practical one if you're not hosting/being hosted on W2k8 (or higher).
The web.config can only set up errors pages for pages controlled by it's web site. If you have any other pages outside the purview of the ASP.Net application, then you set up handling for them in IIS. There's an option in there for configuring the 404 page where you can point it to your custom page.
Only other thing i can think of is passing ALL extensions to asp.net.
This way all types of files get processed by asp.net and your custom error page will work.
In the IIS application configuration, you can set a wildcard mapping (".*") to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
You can setup wild card mapping in IIS (Application configuration/Mappings/Wildcard mappings/ - just set aspnet_isapi.dll as executable and uncheck the Verify that file exists box) that will route all incoming requests to your app - so you can control the behavior directly from it.
You don't have to setup static page in your IIS application settings. Imho, you should be able to setup valid url (e.g. /error_handler.aspx) from your app that will be used as landing page in case of specific server error.
In IIS you can set a Custom Error for 404 errors and direct it to a URL in the site properties.
It shows a static html by default
C:\WINDOWS\help\iisHelp\common\404b.htm
You can change it to a relative url on your site.

Resources