title: ASP.NET MVC: How to get route values
body: <p>I need to get the value of language parameter i tried this code </p>
  
  <pre><code>if(HttpContext.Current.Request.RequestContext.RouteData.Values["language"] == null)
   {
      HttpContext.Current.Request.RequestContext.RouteData.Values["language"] =   "en-US";
  
  }
  </code></pre>
  
  <p>the above code makes the url like the following which is very good </p>
  
  <p><a href="http://localhost:25576/en-US/Home" rel="nofollow noreferrer">http://localhost:25576/en-US/Home</a></p>
  
  <p>the problem is when the user enters <a href="http://localhost:25576/Home" rel="nofollow noreferrer">http://localhost:25576/Home</a> (without en-US)
  the value of  <code>HttpContext.Current.Request.RequestContext.RouteData.Values["language"]</code> becomes "Home"</p>
  
  <p>My question is how to get the real value of language parameter if the user removes en-US or  if the user enters <a href="http://localhost:25576/Home" rel="nofollow noreferrer">http://localhost:25576/Home</a></p>
  
  <p><strong>RouteConfig</strong></p>
  
  <pre><code>  public static void RegisterRoutes(RouteCollection routes)
          {
              routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
              routes.MapRoute(
                name: "DefaultLocalized",
                url: "{language}/{controller}/{action}/{id}",
                defaults: new
                {
                    controller = "Home",
                    action = "Index",
                    id = UrlParameter.Optional,
                    language = ""
  
                }
                    );
           }
  </code></pre>