0

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?

tereško
  • 58,060
  • 25
  • 98
  • 150
Max
  • 6,901
  • 7
  • 46
  • 61

2 Answers2

4

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

Juha Palomäki
  • 26,385
  • 2
  • 38
  • 43
0

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.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • That's what I thought at first, but the characters are on the browser's location before the first script is loaded, so I can't see how it would be responsible. – Max Sep 02 '11 at 20:00
  • @Max, as I said, nothing to do with ASP.NET MVC. It's a client scripting problem. Try disabling javascript on your browser to see if this happens. – Darin Dimitrov Sep 02 '11 at 20:02
  • I disabled javascript in both FF and Chrome and the hash characters are still being appended. – Max Sep 02 '11 at 20:11
  • @Max, do you have something suspicious in your route definitions? I am starting to worry :-) A virus? – Darin Dimitrov Sep 02 '11 at 20:13
  • Chrome lists the query string params in the Network inspector as `a: 1#_#_` – Max Sep 02 '11 at 20:14
  • I've got one route map: routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "mycontroller", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); – Max Sep 02 '11 at 20:18
  • @Max, standard stuff. There gotta be something else going on. What happens if you create a new ASP.NET MVC project from scratch and try to redirect from one controller action to another? – Darin Dimitrov Sep 02 '11 at 20:19
  • Last I checked, it seemed related to Facebook API: http://stackoverflow.com/questions/7131909/facebook-callback-appends-to-return-url – Max May 23 '13 at 14:21