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

我有一个返回重定向的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);
    });

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....