开发者

mapRoute to a Web Form using ASP.NET 4

I have a Url like this

http://localhost:4737/Site/listing/NH/Plaistow/2831516

and I want it to reroute to

http://localhost:4737/Site/listing.aspx

I was reading how to do this for Web Forms here https://web.archive.org/web/20211020111718/https://www.4guysfromrolla.com/articles/012710-1.aspx

Here's what my route looks like.

  routes.MapRoute(
  "FriendlyUrl",
  "Site/listing/{state}/{town}/{mlsnumber}",
  "~/Site/listing.aspx");

In my listing开发者_JAVA百科 page I plan on accessing the following variables

  Page.RouteData.Values["state"]
  Page.RouteData.Values["town"]
  Page.RouteData.Values["mlsnumber"]

But when I navigate to http://localhost:4737/Site/listing/NH/Plaistow/2831516, I just get a HTTP 404 error.

I know how to get this working with MVC, but this is a fairly large application, all written with web forms, so rewriting isn't feasible.

Any ideas on how to troubleshoot this would be helpful.

Thanks !

Here is the working code. Thank you to mrchief for helping me resolve this.

  routes.MapPageRoute(
  "FriendlyUrl",
  "listing/{state}/{town}/{mlsnumber}", 
  "~/listing.aspx");  


Yore doing it the other way. If you're using WebForms, you need to implement UrlRoutingModule as shown here: https://web.archive.org/web/20201205221404/https://www.4guysfromrolla.com/articles/051309-1.aspx

The Routing Rules were designed for use in ASP.Net MVC applications where you redirect a Url to its appropriate Controller (Page in WebForms) with action params (query params in WebFroms parlance).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜