加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 自定义协议MVC Redirect在Chrome中工作但不在IE中工

发布时间:2020-12-16 09:55:13 所属栏目:asp.Net 来源:网络整理
导读:我有一个返回重定向的ActionResult: public ActionResult TeamviewerConnect(int id) { snipped ... return Redirect("impacttv://" + Endpoint.tbl_computerinfo.FirstOrDefault().teamviewerID + "::" + teamviewerPassword); } impacttv://是一个自定义
我有一个返回重定向的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);
    });

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读