自定义协议MVC重定向可在Chrome中运行,但不能在IE中运行 [英] Custom protocol MVC Redirect working in Chrome but not IE
问题描述
我有一个ActionResult返回重定向:
I have an ActionResult that returns a redirect:
public ActionResult TeamviewerConnect(int id)
{
snipped ...
return Redirect("impacttv://" + Endpoint.tbl_computerinfo.FirstOrDefault().teamviewerID + "::" + teamviewerPassword);
}
impacttv://是自定义协议,在IE和Chrome中作为标准链接都可以正常工作.
impacttv:// is a custom protocol and works fine in both IE and Chrome as a standard link.
这在Chrome浏览器中工作正常,但在IE中却是404s-任何人都有想法吗?
This works fine in Chrome, but 404s in IE - anyone have an idea?
推荐答案
请参阅:错误重定向到自定义URL协议.
I know this has been a while since you asked, but this blog post describes the redirect behaviour for custom protocols.
坏消息是重定向不适用于IE.
The bad news is that redirects don't work for IE.
这表示IE无法执行此操作.我最好的建议是为重定向创建一个特殊的视图,并进行元重定向或使用JavaScript设置window.location
.
This says that IE cannot do this. My best advice would be to create a special view for your redirect and have either a meta redirect or use JavaScript to set the window.location
.
另一种选择是作为MVC WebApi AJAX方法进行初始调用,返回Uri,然后设置位置,以使用户不会离开开始"页面.我以前使用过最后一种方法,可以确认它确实有效.
The other option is to do the initial call as a MVC WebApi AJAX method, return the Uri and then set the location so that the user does not navigate away from the 'starting' page. I have used this last method before and can confirm that it definitely works.
您需要安装Mvc WebApi nuget软件包,以及可能不记得的其他一些软件:p
You need to get the Mvc WebApi nuget package installed and probably a few others that I can't remember off the top of my head :p
TvController.cs
public class TVController: ApiController
{
[HttpGet]
public string TeamviewerConnectUri(int id)
{
return "impacttv://" + Endpoint.tbl_computerinfo.FirstOrDefault().teamviewerID + "::" + teamviewerPassword;
}
}
JS(在MVC项目中默认使用jQuery,因为它是jQuery)
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(在MVC项目中默认使用jQuery,因为它包含jQuery)
var apiUrl = '/tv/TeamviewerConnectUri';
$.get(apiUrl, {id: 1 })
.then(function(data)) {
window.location = data.uri;
// window.open(data.uri);
});
这篇关于自定义协议MVC重定向可在Chrome中运行,但不能在IE中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!