ASP.NET web pages without aspx file extension - asp.net

What is best solution to serve ASP.NET web pages without aspx extension? I want to make http://www.mydomain.com/mypage instead of http://www.mydomain.com/mypage.aspx
I use .NET 2.0 and IIS6

If you can upgrade to .Net 4.0,which got a built-in URL Routing feature to do it for you easily,read this article by Scott Mitchel
otherwise if you don't want to move to .net 4.0,read this article by Scott Gu

Url rewriting.
For .NET there are already modules available like this one.

For IIS 6.0 you can use ionics ISAPI URL Rewrite filter http://iirf.codeplex.com/ for extention less urls

Related

Remove aspx extension from SharePoint pages

I would like to remove the ".aspx" extension from pages in a SharePoint web application. This can be done with URL rewriting in IIS web applications, but I cannot find any way to achieve this is SharePoint site pages.
e.g. abcsite/pages/default.aspx should be abcsite/pages/default.
I don't know much about Sharepoint but you can use Url Routing with ASP.NET as an alternative to IIS Rewrite Modules.
One advantage being that forms post back to the correct URL which I prefer (without having to reverse map using IIS Url Rewriting)
Note: Available from .NET 4.0
I am not sure which version of sherepoint you are using.
You can use IIS URL Rewrite 2.0 module
Please have a look at these example which has setp by step instructions
IIS7 URL Rewrite module
SharePoint 2010 with IIS URL Rewrite 2.0
URL Routing with ASP.NET 4.0

How does ASP.NET WebPages implement extensionless URLs?

I'd like to implement the same thing for my own build providers.
I'm talking about an ASP.NET Webpages application, in Visual Studio: File > New Website > ASP.NET Website (Razor)
Works with Cassini, so it's not an IIS Express thing.
I found it, it's an HTTP module, System.Web.WebPages.WebPageHttpModule
This module checks if the file exists, and if it does it creates a handler from that file and remaps the request to that handler.
Razor is a templating engine. It has nothing to do with URLs. They are handled by the ASP.NET routing engine. Extensionless URLs are supported starting from IIS 7.0. In IIS 6.0 you need to associate the aspnet_isapi extension with all incoming requests if you want to support extensionless urls.
I found this information in regard to the "Routing" that you might find handy if you are building an ASP.Net WebPages site w/o MVC3 and wanted to mention it.
Creating More Readable and Searchable URLs - About Routing
HTH

Having URL without .aspx extension

I noticed a lot of ASP .Net sites does not have the URL ending with ".aspx".
An example would be:
- https://stackoverflow.com/questions
Did they create a Questions folder and put a Default.aspx inside?
In that case, wouldn't there be A LOT of default.aspx in many folders which is hard to maintain (even though it is user-friendly)?
Thanks y'all.
StackOverflow is written using ASP.NET MVC. The MVC framework does not use .aspx files.
The way it works internally is by using routing tables - see an overview here.
You can also do this with ASP.NET and .aspx files or you can use URL rewriting. You can read about the differences here.
You can refer to any URL rewriter or a routing technique for that. If you look at the new AS{.NET MVC, it works on that model only.
You can use Url Rewriter to remove extensions from the urls of your website.
ASP.net has a routing framework you can use even if you are not using ASP.net MVC
Official documentation: http://msdn.microsoft.com/en-us/library/cc668201.aspx
Also as previously stated ASP.net MVC works like this out of the box and you can also use URL Rewriting
With ASP.NET 4.0, you get the benefits of URL routing (nice, clean URLs) with ASP.NET webforms, too — see:
Routing for Web Forms in ASP.NET 4.0
URL Routing with ASP.NET 4 Web Forms (VS 2010 and .NET 4.0 Series)
Basically, what you do is define a route like
/question/{id} or /question/{title}
and you then define what ASPX page this is being routed to. Quite nifty!

URL rewriting in asp.net for content management system

URL rewriting in asp.net for content management system
Url Rewriting with ASP.NET by Scott Guthrie
URL Rewriting in ASP.NET by Scott Mitchell
I've done old-school URL Rewriting in ASP.NET and it works, but I'd really recommend that you look into using Routing instead. It works with ASP.NET Webforms as well as MVC, and it's more smoothly baked into the ASP.NET system.
One other option you can look into is the IIS URL Rewriting module. It's worked well for me.

URLs like ASP.NET MVC offers

Is there any way to implement a URL mechanisim in asp.net like it has in asp.net mvc
e.g. mydomain.com/user/myusername but without using the MVC
if so, how?
You do this by using the System.Web.Routing assembly
Here's a blogpost showing how :-)
You can use the same routing mechanism that ASP.NET MVC uses inside of an ASP.NET WebForm application. Check this post by Phil Haack on how to learn more about it.
or
If you don't want to use the routing feature and you want to roll your own, check this question out.
If you have access to IIS:
If it is IIS7, the URL Rewriting module might work.
Set IIS up to process ANY request with ASP.NET, and add an entry to Global.ashx
If it is Apache, use mod_rewrite.
Otherwise, you could use:
http://myserver/Web.aspx/url/1
or:
http://myserver/Url.aspx/1
and process Request.Uri.PathInfo
It has to go to a .aspx file somewhere, as otherwise it will not be processed.
I've done this in the past with ASP.NET 2.0 and the UrlRewrite.Net library
The only trick is that if you want it to work with paths that don't have aspx extensions, you have to configure IIS to pass every request through the ASP.NET engine.
I built a classic ASP.NET (I can't believe this term exists) application around 2005 that used rewriting, and this article on MSDN was very helpful at the time: http://msdn.microsoft.com/en-us/library/ms972974.aspx.
If you're constrained to 2.0, or even 1.1, this may be the way to go, as System.Web.Routing is 3.5 only.
IIRF does URL Rewrite for IIS5 and 6.
It supports Regex. Free. Open source.

Resources