1

Okay guys, so I've been stuck for at least 2 days, with googling and checking out all other stack articles I could find.

I just want to check to see if the first parameter in my route is a valid culture name, and if it isn't modify the url/route before execution to include a culture value.

Is that so hard?! I don't think it should be.

I could just modify things in a basecontroller class, from which all other controllers inherit, and check there and then modify all route data and send it on its way. The problem lies with some other custom routes I have.

Okay, so here's the problem with my code, and why I think it would be easiest to do before execution of any controllers.

 routes.MapRoute(
            "Localization",
            "{lang}/{controller}/{action}",
            new { lang="en-US",controller="Home",action="Index"}
            );
        routes.MapRoute(
           "Solutions",
           "{lang}/Solutions/{controller}/{action}",
           new { lang="en-US", controller = "WhatWeDo", action = "Index"}
          );
        routes.MapRoute(
            "Default", // Route name
            "{lang}/{controller}/{action}/{id}", // URL with parameters
            new { lang = "en-US", controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

So, if I try to modify things, I run into this nasty /solutions/ custom route for certain solutions, and for other answers it requires a custom redirect (Yielding a permanently moved error), and checking to see if certain parameters are null.

Is there any way to extract the route data and modify my route/url in the global.asax file? It would be easiest there, and I really would like to just plop it in so that it's always there, and I can just route normally.

I'm probably not making a whole lot of sense, but I'm a bit frustrated. Any suggestions?

2
  • So, I decided to just keep a lang parameter for all my routes, and just bite the bullet and modify every single routlink and actionlink to include it in the routedata. However, I would like to know if anybody has a solution for this, so I'll leave it up for a few days. Commented Jan 10, 2012 at 19:50
  • I'm not quite sure what the problem is. Explain what you would like this code to do and what it's actually doing. Commented Jan 17, 2012 at 22:34

1 Answer 1

1

I am not totally sure about what you are trying to achieve, is it to "enforce" language in routes?

You could try writing your own RouteHandler to handle things?

I wrote about something similar on my blog.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah this is kind of what I was trying to do. I'll give you credit for the answer because it seems like this is kind of what I wanted to do. Enforcing the language in routes would be the best solution here, and it probably would require what you suggest. Thanks. I'll probably implement this later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.