5

I have a problem. When I try to redirect user to non-http URL from MVC action, it returns:

Object moved to here.

Full response (from Fiddler):

HTTP/1.1 301 Moved Permanently
Cache-Control: private
Content-Type: text/html; charset=utf-8
Location: myGame-app://test.somespecificdata
Server: Microsoft-IIS/8.0
X-AspNetMvc-Version: 4.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcUGlvdHJcRGVza3RvcFxUYWtlc0NhcmVcVGFrZXNDYXJlXERvY3RvcnNcRWRvY3RvclxDb25zdWx0YXRpb25cMTkx?=
X-Powered-By: ASP.NET
Date: Thu, 18 Jun 2015 18:19:35 GMT
Content-Length: 457

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="myGame-app%3a%2f%2ftestprotocol.somespecificdata">here</a>.</h2>

<!-- Visual Studio Browser Link -->
<script type="application/json" id="__browserLink_initializationData">
    {"appName":"Firefox"}
</script>
<script type="text/javascript" src="http://localhost:53098/4c9c75263d91451fa797f9041e4bd0f3/browserLink" async="async"></script>
<!-- End Browser Link -->

</body></html>

My action (with pseudo code):

[HttpGet]
public ActionResult Consultation(int id)
{
      //.. specific business logic
      if(IsMobile()){
          return RedirectPermanent("myGame-app://test.somespecificdata"); 
      }
      else{
          return View("AboutGame", SomeSpecificModel);
      }
}

The same situation is with return Redirect() instead of return RedirectPermanent().

My main goal is to redirect a user who uses the mobile browser to URL with special protocol (not http). This special protocol (myGame-app://) runs my mobile app according to this Stack discussion. How can I achieve this, without information Object moved to here?

Regards

Community
  • 1
  • 1
whoah
  • 4,013
  • 10
  • 47
  • 81

1 Answers1

0

The Redirect/RedirectPermanent methods add a body to the response containing the "moved here"-HTML. If you want an "empty" response just set the response yourself:

HttpContext.Current.Response.Redirect("url", false);
HttpContext.Current.Response.StatusCode = 301;
HttpContext.Current.ApplicationInstance.CompleteRequest();

Be aware that the rest of your logic after this will be executed, so make sure nothing else (filters etc) that might redirect the response again happens after setting this.

svanelten
  • 477
  • 2
  • 14