I use navigation like this:
<a href="/MyMessages/?messageId=1"> First message </>
But before the user is navigated I handle the event in JavaScript:
$('a').on('click', function (event) {
event.preventDefault();
// Do stuff
// Navigate:
location.pathname = $(this).attr('href'); // href is /MyMessages/?messageId=1
});
But it gets encoded in browser, and the address is:
localhost:52500/MyMessages/%3FmessageId=1
and the mvc routing fails:
Server Error in '/' Application.
A potentially dangerous Request.Path value was detected from the client (?).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: A potentially dangerous Request.Path value was detected from the client (?).
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (?).]
System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +9807692
System.Web.PipelineStepManager.ValidateHelper(HttpContext context) +53
But when I just navigate by deeplinking like
localhost:52500/MyMessages/?messageId=1
everything works.
How to avoid my browser encoding my url and preventing the error I get?