重定向返回“对象移动到”

时间:2015-06-19 04:18:46

标签: c# asp.net .net asp.net-mvc asp.net-mvc-3

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

  

对象移到这里。

完全回复(来自Fiddler):

 MimeMessage message = mailSender.createMimeMessage();

 MimeMessageHelper mh = new MimeMessageHelper(message, true, "UTF-8");
 Multipart multipart = new MimeMultipart();
 MimeBodyPart messageBodyPart1 = new MimeBodyPart();

 mh.setTo(to);
 mh.setFrom(from);
 mh.setSubject(subject);
 mh.setText(content, true);

 String attachmentName = "cây chàm sự kiện.pdf";

 if (!StringUtils.isEmpty(attachmentName) && attachmentData != null)
 {
   when i am coverting String to utf - 8 its not getting propet but when i am printing this value i am getting proper output but attachment file name was not getting properly
   mh.addAttachment(attachmentName, new ByteArrayResource(attachmentData));
 }
 mailSender.send(message);

我的行动(使用伪代码):

val query = slickLoginInfos join slickUserLoginInfos on 
   ((l,ul) => l.id === ul.loginInfoId) 
db.run((for { (l, ul) <- query } yield (ul)).result.headOption)

同样的情况是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); } }

我的主要目标是将使用移动浏览器的用户重定向到具有特殊协议(不是http)的URL。此特殊协议(return Redirect())运行我的移动应用according to this Stack discussion。如果没有信息return RedirectPermanent()

,我怎样才能做到这一点

此致

1 个答案:

答案 0 :(得分:0)

Redirect / RedirectPermanent方法将一个正文添加到包含&#34;移动到这里&#34; -HTML的响应中。 如果你想要一个空的&#34;响应只是自己设置响应:

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

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