我有一个返回重定向的ActionResult:
public ActionResult TeamviewerConnect(int id) { snipped ... return Redirect("impacttv://" + Endpoint.tbl_computerinfo.FirstOrDefault().teamviewerID + "::" + teamviewerPassword); }
impacttv://是一个自定义协议,在IE和Chrome中都可以作为标准链接使用.
这在Chrome中运行良好,但IE浏览器中的404s – 任何人都有想法?
解决方法
见:
Error redirecting to a custom URL protocol.
I kNow this has been a while since you asked,but 07001
describes the redirect behavIoUr for custom protocols.The bad news is that redirects don’t work for IE.
这说IE不能这样做.我最好的建议是为您的重定向创建一个特殊视图,并使用元重定向或使用JavaScript来设置window.location.
另一个选项是作为MVC WebApi AJAX方法进行初始调用,返回Uri然后设置位置,以便用户不会离开“起始”页面.我以前使用过最后一种方法,可以确认它确实有效.
MVC WebApi
你需要安装Mvc WebApi nuget软件包,可能还有其他一些我无法记住的其他软件包:p
TvController.cs
public class TVController: ApiController { [HttpGet] public string TeamviewerConnectUri(int id) { return "impacttv://" + Endpoint.tbl_computerinfo.FirstOrDefault().teamviewerID + "::" + teamviewerPassword; } }
JS(使用jQuery,因为它默认包含在MVC项目中)
var apiUrl = '/api/tv/TeamviewerConnectUri'; $.get(apiUrl,{id: 1 }) .then(function(uri)) { window.location = uri; // window.open(uri); });
标准MVC方式
TvController.cs
public class TVController: ApiController { [HttpGet] public ActionResult TeamviewerConnectUri(int id) { return Json(new {uri = "impacttv://" + Endpoint.tbl_computerinfo.FirstOrDefault().teamviewerID + "::" + teamviewerPassword},JsonRequestBehavior.AllowGet); } }
JS(使用jQuery,因为它默认包含在MVC项目中)
var apiUrl = '/tv/TeamviewerConnectUri'; $.get(apiUrl,{id: 1 }) .then(function(data)) { window.location = data.uri; // window.open(data.uri); });
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。