asp.net mvc url routing - asp.net

i have a classic web project and i want to use asp.net mvc url routing just for rewrite url. is it possible without make much changes to my web project?

Routing is not part of ASP.NET MVC - it's just part of ASP.NET itself. The good news is that it works with both MVC and WebForms (ASPX files). Check out Phil Haack's blog post on how to get this to work.
The only changes you need to make to your application are to add some configuration items to web.config and then register your routes in global.asax.cs (or global.asax.vb if you're using VB).

System.Web.Routing, while shipped with ASP.NET MVC, is not technically part of the MVC framework. You can in fact use it as part of a regular ASP.NET webforms project.

Definitly possible for .net 4.0, so like in 2 months.
Also, google shows alot of content on how to do it today.

As others have said routing is now built into .net 4 and can be used for both mvc and web forms. ScottGu has a post about how to use routing in webforms and can be found here.
Hope it helps.

Related

how to hide aspx extension(URL rewriting) using global.asax in asp.net

I am working on URL rewriting using global.asax in asp.net 3.5,
URL:http://localhost:65278/URL_EG2/SubFolder/Home.aspx
I want it to rewrite as:http://localhost:65278/Home
How to acheive this? Can anyone give me simple EG?
I assume you are using ASP.NET web forms.
If you use Routing for Web Forms then you don't need to have extensions on the url. You can have the same routing goodness experienced by the MVC apps in your web forms applicaiton as well.
Check here to learn more about Routing for ASP.NET Web Forms

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!

How to get started with URL Routing in an asp.net webform application?

Thus far working with asp.net webforms was very easy .... But never implemented URL Routing in webforms... I know asp.net MVC Handles URL Routing pretty well...
How to get started with URL Routing in an asp.net webform application?
For EX:
Say http://www.mydomain.com/Forms/Category.aspx i want it to be like http://www.mydomain.com/Forms/Category
Any good article to start with URL Routing asp.net 3.5
Using ASP.NET Routing Without ASP.NET
MVC
Routing with ASP.NET Web Forms
Using Routing With WebForms. by Phil Hack
ASP.NET Routing
hope this helps

Integration ASP.NET web forms blogging framework into ASP.NET MVC

Is there any way to use something like BlogEngine.NET (a blogging framework developed on the ASP.NET web forms model) in an ASP.NET MVC application? I want something where I can simply go to http://rooturl/blog and have it fire up the BlogEngine.NET site. I'm assuming that the ASP.NET MVC framework will intercept this call however and try to route it to the "BlogController"'s Index function though. Is there any way around this or is this a non-issue?
Scott Hanselman wrote on this a while back:
Plug-In Hybrids: ASP.NET WebForms and ASP.MVC and ASP.NET Dynamic Data Side By Side
But if I recall correctly, if you don't have a controller that matches /blog then the engine will default to sending the request to your /blog folder, and away you go, on top of that, as Scott notes:
Why doesn't ASP.NET MVC grab the request? Two reasons. First, there's an option on RouteCollection called RouteExistingFiles. It's set to false by default which causes ASP.NET MVC to automatically skip routing when a file exists on disk.
However, he goes on to note that you could just add the following at the top of your route definitions:
routes.IgnoreRoute("blog/{*pathInfo}");
Which would then ignore all requests to /blog/

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