Max
Max

Reputation: 7119

.net MVC RedirectToAction odd characters appended to URL

I'm doing a RedirectToAction like this:

  return RedirectToAction("index", "mycontroller", new RouteValueDictionary(
    new {
      a = 1
    }
  ));

But when I'm redirected, the URL has some odd characters at the end, namely #_#_ so it looks like this:

http://mysite.com/?a=1#_#_

I'm a little confused how those characters are getting there, seeing as I'm not appending them. Any ideas?

Upvotes: 0

Views: 1249

Answers (2)

Juha Palomäki
Juha Palomäki

Reputation: 27032

Is the browser being redirected to your action from Facebook? Facebook is at least adding this kind fragments to redirect URLs for security reasons. And browsers seem to be doing little magic with these fragments:

After much debugging, I realized that Firefox, Chrome, and Opera will re-attach a URL Fragment after a HTTP/3xx redirection has taken place, even though that fragment was not present in the URL specified by the Location header on the redirection response.

Source: http://blogs.msdn.com/b/ieinternals/archive/2011/05/17/url-fragments-and-redirects-anchor-hash-missing.aspx

Upvotes: 4

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

This has nothing to do with ASP.NET MVC. You probably have some client side javascript or plugin which does this and appends a fragment to the url. Or maybe some plugin on your browser. Note that you can append fragments to the url (everything that follows the # sign) using javascript without the browser redirecting.

Upvotes: 0

Related Questions