1

I have set up two custom extensions to enable MVC in IIS6.

So the site can be accessed with a URL of either something like...

mysite/mycontroller.europe/myaction

or like...

mysite/mycontroller.america/myaction

What is the most robust way of finding the extension from the RequestContext instance?

So I would like to be able to write something like...

var location = reqContext.......GetExtenstion(); // location = "europe"

and obviously have that work even if the setup of the site/directories changes a little.

fearofawhackplanet
  • 52,166
  • 53
  • 160
  • 253

2 Answers2

2

Define a route:

routes.MapRoute(
    "DefaultWithExtension",
    "{controller}.{extension}/{action}",
    new { controller = "Home", action = "Index", extension = "america" }
);

and then:

var extension = RequestContext.RouteData.GetRequiredString("extension");
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

Also you can just define extension as a string parameter for all relevant actions for the controllers, in which case it will be directly available. e.g.

public ActionResult myaction(string extension)

This does still need the mapRoute entry defined above.