URL Routing to Default Page
I have an asp.net 4.0 web forms app setup with url rereouting. In development, my app's URL looks perfect. I have a page called enrollnow.aspx that responds to the routing, so if I type in localhost/enrollnow/abc, my app responds as expected.
Once promoted into my staging environment however, the URL is off. I have a domain, and a virtual dir created off of my domain called "enrollnow". So basically, my URL outside of development is: mydomain.com/enrollnow/enrollnow/abc - where the first enrollnow is the directory, the second enrollnow is the page name, and the abc is my route value.
Is there any way I can have the "default page" respond, so the second enrollnow (which is enrollnow.asp) isnt required? Perhaps I can rename my enrollnow.aspx page to default.aspx, or I can change the mapping in my routetable? Heres my routetable, incase that helps. thanks!
Routetable:
RouteTable.Routes.Add("PURLRoute", New Route("EnrollNow/{PURL_ID}", New PageRouteHandler("~/EnrollNo开发者_运维知识库w.aspx")))
I'd try to omit "EnrollNow/" in your route:
RouteTable.Routes.Add("PURLRoute", new Route("{PURL_ID}",
new PageRouteHandler("~/EnrollNow.aspx")))
BUT: The problem will be for the routing table to distinguish between a parameter value and a route to another page. For instance, say, you have another route:
RouteTable.Routes.Add("AnotherRoute", new Route("AnotherPage",
new PageRouteHandler("~/AnotherPage.aspx")))
Then the behaviour when specifying the URL mydomain.com/enrollnow/AnotherPage
will depend on the order you added the two routes above. If "PURLRoute" is added before "AnotherRoute" the URL will be routed to "EnrollNow.aspx" and "AnotherPage" will be interpreted as a parameter value for {PURL_ID} (which you probably don't want). If "PURLRoute" is added after "AnotherRoute" you will be routed to "AnotherPage.aspx" (which is good, I think) but then you can never specify "AnotherPage" as a value for {PURL_ID}.
精彩评论