title: ASP.NET Passing Parameter in URL
body: <p>I wrote a very simple web app in Flask and am porting it to ASP.NET Framework. All the functionality is in JavaScript and HTMl, so the framework should just act as scaffolding. I've got almost everything ported over, except for what seems to be a routing issue. My site expects a string token variable to be appended to the URL, like so: <code>www.mysite.com/token-string</code>. For development, the URL is <code>localhost:*****/string-token</code>, with my <code>Index.cshtml</code> page being displayed as default.</p>
  
  <p>When I pass the URL without the token it works fine and my index page loads. However I get a 404 when I try it with the token. I'm assuming it's identifying the token as a route and is trying to navigate to it? I'm not sure how to fix it. Here are the important parts of my code:</p>
  
  <p><strong>HomeController.cs:</strong></p>
  
  <pre><code>public class HomeController : Controller
  {
      public ActionResult Index(string token)
      {
          return View();
      }
  }
  </code></pre>
  
  <p><strong>RouteConfig.cs:</strong>
  NB: I've not changed this, not sure what to do with it.</p>
  
  <pre><code>public class RouteConfig
  {
      public static void RegisterRoutes(RouteCollection routes)
      {
          routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
          routes.MapRoute(
              name: "Default",
              url: "{controller}/{action}/{id}",
              defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
          );
      }
  }
  </code></pre>
  
  <p>It's quite important that the token is passed in the way it is, rather than as a <code>?</code> query parameter or anything like that. Additionally, the C# index view doesn't really need to do anything with the token - it gets extracted by the JavaScript.</p>
  
  <p>Any advice is most welcome. Thanks.</p>