Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Illegal characters in path depending on User-Agent?

I have two identical calls to ASP.NET, the only difference is the User-Agent. I used Fiddler to reproduce the issue.

The HTTP request line is:

PUT http://localhost/API/es/us/havana/club/tickets/JiWOUUMxukGVWwVXQnjgfw%7C%7C214 HTTP/1.1

Works with:

User-Agent: Mozilla/5.0 (Linux; Android 4.3; Nexus 10 Build/JSS15Q) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2307.2 Safari/537.36

Fails with:

User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4

Everything else is 100% the same.

like image 477
user2105237 Avatar asked Nov 13 '15 14:11

user2105237


1 Answers

In my case, the root cause was MVC's MultipleViews and DisplayMode providers. This allows MVC apps to magically pick up device-specific views; e.g. custom.cshtml customer.mobile.cshtml

This article has a good explanation of the functionality as well as details how to turn it off: https://msdn.microsoft.com/en-us/magazine/dn342866.aspx

I fixed this by adding Microsoft.AspNet.WebPages package to my project and adding a call to this code in my startup (application_start in global.asax or if using OWIN, the method decordated w/ OwinStartup attribute):

public static void RegisterDisplayModes()
{
    // MVC has handy helper to find device-specfic views. Ain't no body got     time for that.
    dynamic modeDesktop = new DefaultDisplayMode("") { ContextCondition = (c => { return true; }) };
    dynamic displayModes = DisplayModeProvider.Instance.Modes;
    displayModes.Clear();
    displayModes.Add(modeDesktop);
}
like image 122
Mark Nadig Avatar answered Nov 12 '22 19:11

Mark Nadig