how do i make my web app friendly URL?
currently my app URL looks like this
http://www.domain.com/Page.aspx?article=103
but I would like to display the URL to look like this
http://www.domain.com/Page.aspx?Google-likes-url-friendly
what would i need to do?
check out
http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/
you will need to download and install a module.
Pretty easy to use and configure.
Here is the introduction :
http://learn.iis.net/page.aspx/461/creating-rewrite-rules-for-the-url-rewrite-module/
Look into using ASP.NET MVC. With it, you could have a URL that's even better: http://www.domain.com/Article/Google-likes-url-friendly
If you're using ASP.NET 4.0 or .NET 3.5 SP1 (or ASP.NET MVC), you can use the routing module.
ASP.NET Routing # MSDN
There is a good walkthrough at http://msdn.microsoft.com/en-us/library/dd329551.aspx
Keep in mind the url-rewrite module metioned above only works with IIS7/7.5. And make sure your host, if you are using one, has it installed.
For IIS6, IIS5, take a look here:
Url Rewriting with ASP.NET
ASP.NET routing and URL rewriting will both work. Here are the differences:
http://learn.iis.net/page.aspx/496/iis-url-rewriting-and-aspnet-routing/
Another option is to write a 404 trap: http://codeeleven.blogspot.com/2007/11/rewriting-urls-in-aspnet-without-using.html
Hacky, but an effective last resort.
Use Microsoft.AspNet.FriendlyUrls Nuget Package to Make this easy
Related
I'd like to know if it is possible to have the URLs of the pages of a Webforms application display without the .aspx extension.
For instace, http://stackoverflow.com/questions/ask instead of http://stackoverflow.com/questions/ask.aspx
The technology that stackoverflow uses has been discussed many many times, what you are looking for is the ASP.Net MVC Framework
http://www.asp.net/mvc
https://stackoverflow.com/questions/tagged/asp.net-mvc
This can also be done using URL rewriters
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
This can be done by using either ASP.NET MVC or the routing engine by itself.
You want Asp.Net Routing. Best place to start is here:
http://haacked.com/Tags/Routing/default.aspx
If you are using IIS7 it is easy. IIS6 requires a little more work.
This is generally done using a routing engine in a framework. However if you want to do this for an arbitrary application it's really done using Apache's Mod_Rewrite.
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...
I'd like to know if it is possible to have the URLs of the pages of a Webforms application display without the .aspx extension.
For instace, http://stackoverflow.com/questions/ask instead of http://stackoverflow.com/questions/ask.aspx
The technology that stackoverflow uses has been discussed many many times, what you are looking for is the ASP.Net MVC Framework
http://www.asp.net/mvc
https://stackoverflow.com/questions/tagged/asp.net-mvc
This can also be done using URL rewriters
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
This can be done by using either ASP.NET MVC or the routing engine by itself.
You want Asp.Net Routing. Best place to start is here:
http://haacked.com/Tags/Routing/default.aspx
If you are using IIS7 it is easy. IIS6 requires a little more work.
This is generally done using a routing engine in a framework. However if you want to do this for an arbitrary application it's really done using Apache's Mod_Rewrite.
I have to have my website stored in a subfolder of my domain root. Is there a way to rewrite the URLs so that it doesn't appear to be stored in a subfolder? It doesn't matter to me if this is done at the IIS level or in the web.config.
Have you looked at the routing engine that came out of the MVC project but is now a stand-alone feature of the .NET Framework?
With IIS7, the way to go is probably the module that Microsoft themselves put out:
http://blogs.iis.net/ruslany/archive/2008/11/10/url-rewrite-module-release-to-web.aspx
In previous releases, there were various workarounds with different downsides/costs:
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
If you decide to go with an ISAPI filter, we've had good experiences with Ionic's Isapi Rewrite. And it's free (beer and speech).
I'm using the ManagedFusion Url Rewriter on my blog. I like it because it doesn't need to be installed at the server level.
You can presumably get the behavior you want by using an ISAPI filter.
Google for: rewrite ISAPI filter and you will find some prebuilt examples to try and see what works best for you.
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.