who*_*oah 5 .net c# asp.net asp.net-mvc asp.net-mvc-3
我有个问题.当我尝试将用户从MVC操作重定向到非http URL时,它返回:
对象转移到了这里.
完整回复(来自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>
Run Code Online (Sandbox Code Playgroud)
我的动作(伪代码):
[HttpGet]
public ActionResult Consultation(int id)
{
//.. specific business logic
if(IsMobile()){
return RedirectPermanent("myGame-app://test.somespecificdata");
}
else{
return View("AboutGame", SomeSpecificModel);
}
}
Run Code Online (Sandbox Code Playgroud)
相同的情况是return Redirect()代替return RedirectPermanent().
我的主要目标是将使用移动浏览器的用户重定向到具有特殊协议(不是http)的URL.根据此Stack讨论,此特殊协议(myGame-app://)运行我的移动应用程序.如果没有信息,我怎样才能做到这一点?Object moved to here
问候
小智 0
Redirect/RedirectPermanent 方法将正文添加到包含“移至此处”-HTML 的响应。如果您想要“空”响应,只需自己设置响应:
HttpContext.Current.Response.Redirect("url", false);
HttpContext.Current.Response.StatusCode = 301;
HttpContext.Current.ApplicationInstance.CompleteRequest();
Run Code Online (Sandbox Code Playgroud)
请注意,此后的其余逻辑将被执行,因此请确保在设置此设置后不会发生可能再次重定向响应的其他内容(过滤器等)。