views:

519

answers:

2

I am working on a project that needs to grab the actual URL and use it in the route itself. Everything I am seeing, reading and testing allows the route to grab the items after the site URL. This is what I have tried and each time it simply say the site is blank (which is probably because of the default of blank). Can you throw me any bones on allowing the route to also utilize the root URL? The goal is one website that will process the URL and route me to different guts once inside of the View.

Here is code I have tried but no luck outside of localhost

            routes.MapRoute(
            "PageRouter",
            "{site}/{*url}",
            new { controller = "PageRouter", action = "RoutePage", site = "", url = "" }
        );

Your help is greatly appreciated. Thanks in advance

A: 

How about just using HttpContext.Request.RawUrl inside the action of the controller. I may be missing something here. Where is the url you want to read coming from? Is it the current page or another page?

Nathan Totten
current page is where it is at....we basically need to use the source URL to determine templates once we are inside of the route. The {site} placeholder in the route appears to be too far in past the RawUrl. I'll try using it and offer a comment on how it worked
dodegaard
Nathan....would it be better to do it in the Global.asax.cs instead? Can you harvest info from the HttpContext.Request at that point? We'll need to do this with each request coming into the system to allow for custom templates
dodegaard
A: 

Nathan's answer is part of the answer. The HttpContext.Request.RawUrl allows access to this info but in the Global.asax.cs file instead. This being done in the Application_BeginRequest event. But the trick (and please comment if someone knows a more elegant way to do this) but we inject the Url being used into the remaining route path so it can be picked up in the MapRoute method. So the "http://subdomain.domain.net/url" site would then appear as "http://subdomain.domain.net/subdomain.domain.net/url so it can be picked up in the {site} part of the MapRoute command. This would not be shown to the user but then allows us to make decisions inside the app based on received URL. Does this sound sane? Comments are welcome if this seems a crazy way of doing it in order to absorb the root Url.

dodegaard