ASP.Net MVC 2 Area, SubArea and Routes -


I'm looking for a solution to my problem. I found a lot of similar issues, but none of them Did not lead a solution for.

I am trying to register an area within an area. It works but it screws up my routing "partly"

In order for my registration, consider the route registrations coming from Regional Registration, and the Foo registrations

  routes MapRoute ("FooBar_default", "Foo / Bar / {controller} / {action}", new {domain = "foo / bar", controller = "home", action = "index"}, new [] {BarHomeControllerType.Namespace }); ("Foo_default", "Foo_default", "Foo / {controller} / {action} / {id}", new {domain = "foo", controller = "start", verb = "index", id = UrlParameter.Optional }, New {controller = new NotSubArea ()}, new [] {startController. Namespace}}; Routes.IgnoreRoute ("{} resource .axd / {* pathInfo}"); Routes Marker ("PageRoit", "Page / {Action}", new {controller = "page", action "index"}). Datacaken ["usernamenamepuzzlebackback"] = false; Routes.MapRoute ("default", // root name "{controller} / {action} / {id}", new {controller = "home", action = "index", id = UrlParameter.Optional}, new [] {Typef (home controller) .namespace}) .datacodes ["usernamenamepuzzlebackback"] = false;  

Now the following problem occurs. When those pages are going to the website / foo / or website / foo / bar link, then it is used correctly:

 ! {Html.ActionLink & lt; HomeController & gt; (C => c.index (), "home", new {domain = "foo / bar"}} or! (Url action ("index", "home", new {domain = "foo / bar" "})} // or a different area  

However, when I use it in my main pages, in other words, in the website / or website / home etc.

< Pre> ! {HTML.ActionLink (C => c.index), "home", new {domain = ""}}} or! {Url.Action ("index "," Home ", New {domain =" "}}} /

This URL generates: Website / Foo / Bar / Home etc. D ... which is absolutely wrong

When I remove it area registration for FU / bar, it all works again. URL Website / Home / About or Website / Home Directly displaying the correct pages, so in any way, the internal URL Helper is to choose the wrong routes.

I tried to change the order of FooBar_default and Foo_Default routes, so that Foo_default route FooBar_default Paj Action to be, but the area now have does not work (resources) and links are still generated incorrectly.

I find the odd one that by removing the foo / bar registration the problem is solved. I was hoping that someone could put some insights on this matter ..

You need to understand that one area is just a routing concept that Microsoft has wrapped the concept to start people or URLRating Has been doing.

You can actually get the MVC framework in the way of your request, although you want according to your needs.

What you need to do, writing your own Rothhandler, will enable you to accurately guide that the MVC Framework route requests how to process your needs.

Look for an example to get you started.

The setting indicates that instead of mapping my own IRouteHandler to use your own route, you should get the location you need. It's a bit more trying than using box solutions in areas, but you should get better results.

  route. Map route ("tree", "tree / {* path}", new {controller = "tree", action = "index"}). Touthandler = New Tree Routehandler ();  

Comments