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: www.mysite.com/token-string. For development, the URL is localhost:*****/string-token, with my Index.cshtml page being displayed as default.
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:
HomeController.cs:
public class HomeController : Controller { public ActionResult Index(string token) { return View(); } } RouteConfig.cs: NB: I've not changed this, not sure what to do with it.
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 } ); } } It's quite important that the token is passed in the way it is, rather than as a ? 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.
Any advice is most welcome. Thanks.
www.mysite.com/?token='token-string'to use token string with default route, thus define a route which expectstokenparameter (url: "{controller}/{action}/{token}") wheretokenis a required parameter.www.mysite.com/string-token[Route("~/{token?}")]on yourIndexaction method, which results inwww.mysite.com/string-token. Or define Index action method:url: "{token}"(with default routecontroller = "Home", action = "Index", token = UrlParameter.Optional).