简体   繁体   中英

MVC 4 querystring value with period

I am implementing OAuth2 into my MVC project. At the moment I am working with Google Api. The first step worked fine and my callback URL is being called with a parameter code which looks like this:

code=4/O89-dMqK-MHn8ynzsEawrpYPL80Y.Mu61gsIzfDMYOl05ti8ZT3adNQ17fgI

the problem is that MVC is ignoring it because of the period (.) in the value. I need to know what I can do to get it to work. If I remove the period, then everything works as it should but I have no control over what google send back to me but I need to be able to read it.

I have tried adding a custom route looking like this:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.IgnoreRoute("{*robotstxt}", new { robotstxt = @"(.*/)?robots.txt(/.*)?" });

    // default MVC route
    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    ).RouteHandler = new CmsRouteHandler();

    // OAuth route
    routes.MapRoute(
        name: "OAuth",
        url: "OAuth/OAuth2Callback*"
    );

    // CatchAll route
    routes.MapRoute(
        "Catchall", // Route name
        "{*url}"
    ).RouteHandler = new CmsRouteHandler();
}

but it doesn't appear to work :(

Cheers, /r3plica

If you are using .NET 4.0, add this to system.web section of your web.config file

<httpRuntime relaxedUrlToFileSystemMapping="true" />

It should solve the problem

可能此设置可以解决此问题:
<system.webServer> <modules runAllManagedModulesForAllRequests="true"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM