How to hide/change asp.net page extension from the viewer? - asp.net

How to hide/change asp.net page extension from the viewer at the client-side?
I.e. while accessing a page www.xyz.com/Dir/MyPage.aspx, the viewer would only see www.xyz.com/Dir/MyPage.html or www.xyz.com/Dir/MyPage.

You need to look into using URL rewriting. If you are using IIS 7 then you can use Microsoft URL rewrite. I also use the URL rewrite software ISAPI Rewrite. Basically you'll end up creating rewrite rules to append the .aspx extension to the IIS page requests which have no extension. Then all your links created in your code should be created without the .aspx extension.
I realize this response is a bit abbreviated, but I suggest you start learning about URL rewriting.
EDIT: I'm not sure if you'll get this, but I created a screencast and posted it to my blog which covers the basic idea of how to hide the page extension for ASP.NET. I hope it helps :-)

You can use the routing built into MVC. It's not in any way required to only be used with the MVC Framework, and is quite agnostic.

Related

Can a webform application handle extension less URLS?

Can a webforms application handle extensionless URLS?
The application is running version 4.5
So I want a URL like:
www.example.com/login
to redirect to the actual page like:
www.example.com/users/login.aspx
I am ideally looking for a solution that doesn't require any IIS modification ie. application level only
Sure. There are a bunch of articles that will tell you how. Here are a couple:
https://msdn.microsoft.com/library/dd329551(v=vs.100).aspx
http://weblogs.asp.net/scottgu/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series

URL Rewriting in IIS 6 Using ISAPI_Rewrite 3

I am running into an issue where I am trying to implement SEO friendly links in an ASP.Net 3.5 application with IIS6. The issue is that when I try to use a url like "www.text.com/about/" it isn't directed to the ASP.Net pipeline, so I am unable to route the request to the correct physical aspx file. With ISAPI_Rewrite I know I can redirect a request to the specific page, but is there a way to have a request sent to the ASP.Net pipeline, so I can manipulate the request using the built-in routing engine. Any help is appreciated.
Wade
Wade ,
You can either implement urlmodule which extents ihttpmodule.
or you can implement httphandler , You need to make this entry in httphandler section of web.config , so that each request comes to .net handler , you can customize your path there and rewrite the url
let me know if you need any help.
as sample example
http://www.aspnettutorials.com/tutorials/advanced/httphandler-aspnet2-csharp.aspx
let me know if you need any help , i implemented recently
I found the technet article on how to route wildcard traffic to the asp.net pipeline. Here is the link - http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/5c5ae5e0-f4f9-44b0-a743-f4c3a5ff68ec.mspx?mfr=true.

How to create a blog in ASP.NET and not ASP.NET MVC

I have created a blog application with ASP.NET MVC and MSSQL. I must say, i really enjoyed the process of creating an application with ASP.NET MVC. Clean URLS(with URL routing), No view States and so on.
BUT i was wondering how would this would have been done if i choose web-form style coding? will the aspx would be created in the fly as i create a article.(take this url for ex: http://weblogs.asp.net/scottgu/archive/2010/10/06/announcing-nupack-asp-net-mvc-3-beta-and-webmatrix-beta-2.aspx) though the URL is not clean but still makes sense. if yes then what about its corresponding cs file? if no how is the URL so clean?
Would be great if someone throw some light on how it is done in ASP.NET.
Thank you, Faraaz.
If your using .NET 4, you can make use of MapPageRoute to accomplish the clean URL's with regular Web Forms.
routes.MapPageRoute("MySuperCleanRoute", "some/clean/url", "~/ActualPage.aspx");
With the addition of MapPageRoute, you no longer have the feeling "I should use ASP.NET MVC because i want clean URL's".
Choose ASP.NET MVC if you like the pattern. If your used to Web Forms, use it - and use MapPageRoute to achieve clean URL's (or use a URL Rewriting module if <= .NET 4)
A blog in ASP .NET would have been done in much the same way. The idea is to use one file and URL rewriting. IIS7 has URL rewriting built in but for IIS6 you can use something like ISAPI_Rewrite to handle .htaccess style files (which is what Apache uses).
ASP .NET MVC handles all this for you in its routing but you can do it yourself using a URL rewriting tool. The difference is that for MVC, the application handles the rewriting but ISAPI_Rewrite, IIS Rewriting are done by the server. This can change a URL like http://mysite.com/something/other to http://mysite.com/file.asp?p1=something&p2=other.
The second link is only internal to the server (it doesn't actually change the URL in the user's address bar). In the case of a URL like on Scott's blog, you could store the 'announcing-nupack-asp...' bit in a database as part of the article row so your blog article page has something to look for. The files don't actually exist on the server but the rewriting passes all requests to an existing file with parameters.
Note that this technique is common for lots of different sites - not just blogs. Notice the Stack Overflow URL, Twitter URLs, etc.
MSDN has an old article on URL Rewriting in ASP .NET, along with some examples of filters you can use.
See IIS URL Rewrite Module
You can use the URL Rewriting that is in asp.net MVC with WebForms if you are using .Net Framework 3.5 SP1 (if you don't have access to .Net 4)
Here's an MSDN magazine article explaning...

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!

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