First things first, download the example that he provides in that article - it's at the bottom of the page. You'll learn a lot just looking through this code a bit.
Next, let's assume you set up a named route like this:
**Note: Make sure you play around with this a lot first - some of the routes that I thought would work did NOT work. However, that was mostly because I misunderstood how to use them correctly.
Still, I was wondering one thing. Should I move to MVC if I'm already moving to Routing? - I've tested update panel on a MVC view, postback button.. it seems to work with no problem, at least on the MVC sample I've ran -( the official one with Home, About.).
So left are: 1. will this work on IIS6 and if not how to make it work? :)
2. As my client has some insane rewrite (SEO maniacs) requests, Routing seem like mana from the Heavens for me. What about it's production usability (stability) and what about MVC in the end?
It's really entirely up to you and how comfortable you are with having to make changes. Because it's only a preview at this point, you WILL have to make small changes with each new release as the API changes. See the post
here to get some other people's opinions on this exact question. I tossed around with this question for a while as well, but you have to remember that it's not ASP.NET development as usual. There's some nuances you'll have to
learn, and you'll probably progress a bit slower than normal as you're getting used to it. That's an important question I would ask yourself about your current project - can you afford to take the time to learn while delivering the product? And... can you
afford to take the time to make the small changes when a new release hits?
As far as your question about working on IIS6 - yeah, it should work - although you may have to use the ".aspx" extension for the routes to work (if you're using shared hosting - if you have access to IIS, then you can make the necessary changes yourself
so that the extension is not required)
arrtoodeetoo
0 Points
3 Posts
Routing for WebForms
Mar 25, 2008 04:56 PM|LINK
http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx
I'm using that code as a startup. - However, I'm a bit unclear how do I access URL parameters and how do I pass parameters to URL?
leftend
Member
103 Points
47 Posts
Re: Routing for WebForms
Mar 25, 2008 11:20 PM|LINK
First things first, download the example that he provides in that article - it's at the bottom of the page. You'll learn a lot just looking through this code a bit.
Next, let's assume you set up a named route like this:
routes.Map("General", "haha/{filename}.aspx").To("~/forms/haha.aspx");
Now, your page must extend from RoutablePage, and then you can just access the RouteData, and look in the Values dictionary object, like so:
string fileName = this.RouteData.Values["filename"]
That's it!
**Note: Make sure you play around with this a lot first - some of the routes that I thought would work did NOT work. However, that was mostly because I misunderstood how to use them correctly.
msurface
Member
10 Points
5 Posts
Re: Routing for WebForms
Mar 26, 2008 12:13 AM|LINK
I've had to box RouteData.Values.
So...
string filename = (string)RouteData.Values["filename"];
arrtoodeetoo
0 Points
3 Posts
Re: Routing for WebForms
Mar 26, 2008 12:22 AM|LINK
Got the trick. Nvm.:) Thx.
Seems like this could actually work and replace url rewrite. I like the flexibility I can see and avoidance of the regex hell.-
Haacked
Contributor
6901 Points
412 Posts
Re: Routing for WebForms
Mar 26, 2008 12:42 AM|LINK
And it's bi-directional. So if you use the API to generate URLs and later change your routes, the urls (in theory) should stay in synch.
Senior Program Manager, Microsoft
What wouldn’t you do for a Klondike bar?
arrtoodeetoo
0 Points
3 Posts
Re: Routing for WebForms
Mar 26, 2008 12:54 AM|LINK
Yep, just have changed
routes.Map("Numberz", "boats/" + ldf[0].Value + "/{price}/{boatname}.aspx").To("~/forms/haha.aspx");
to
routes.Map("Numberz", "boats/{price}/{boatname}/" + ldf[0].Value + ".aspx").To("~/forms/haha.aspx");
Still, I was wondering one thing. Should I move to MVC if I'm already moving to Routing? - I've tested update panel on a MVC view, postback button.. it seems to work with no problem, at least on the MVC sample I've ran -( the official one with Home, About.).
So left are: 1. will this work on IIS6 and if not how to make it work? :)
2. As my client has some insane rewrite (SEO maniacs) requests, Routing seem like mana from the Heavens for me. What about it's production usability (stability) and what about MVC in the end?
Thanks.
leftend
Member
103 Points
47 Posts
Re: Routing for WebForms
Mar 26, 2008 06:28 AM|LINK
It's really entirely up to you and how comfortable you are with having to make changes. Because it's only a preview at this point, you WILL have to make small changes with each new release as the API changes. See the post here to get some other people's opinions on this exact question. I tossed around with this question for a while as well, but you have to remember that it's not ASP.NET development as usual. There's some nuances you'll have to learn, and you'll probably progress a bit slower than normal as you're getting used to it. That's an important question I would ask yourself about your current project - can you afford to take the time to learn while delivering the product? And... can you afford to take the time to make the small changes when a new release hits?
As far as your question about working on IIS6 - yeah, it should work - although you may have to use the ".aspx" extension for the routes to work (if you're using shared hosting - if you have access to IIS, then you can make the necessary changes yourself so that the extension is not required)
Hope that's helpful.