gpt4 book ai didi

c# - 重定向返回 "Object moved to"

转载 作者:太空狗 更新时间:2023-10-29 23:50:34 28 4
gpt4 key购买 nike

我有一个问题。当我尝试将用户从 MVC 操作重定向到非 http URL 时,它返回:

Object moved to here.

完整响应(来自 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>

我的操作(伪代码):

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

同样的情况是 return Redirect() 而不是 return RedirectPermanent()

我的主要目标是将使用移动浏览器的用户重定向到具有特殊协议(protocol)(不是 http)的 URL。这个特殊协议(protocol) (myGame-app://) 运行我的移动应用 according to this Stack discussion .如果没有信息 Object moved to here,我该如何实现?

问候

最佳答案

Redirect/RedirectPermanent 方法将正文添加到包含“移至此处”-HTML 的响应中。如果您想要“空”响应,只需自己设置响应:

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

请注意,在此之后您的其余逻辑将被执行,因此请确保在设置此后不会再发生任何可能重定向响应的其他内容(过滤器等)。

关于c# - 重定向返回 "Object moved to",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30929818/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com