Asp.net(核心) - 导航到多个URL

时间:2017-08-30 22:18:04

标签: asp.net razor asp.net-core-mvc response.redirect

使用Custom URL Protocol我为自己设置了一个名为更新程序的网址,这意味着当我调用以下控制器时;

第一个例子:

public IActionResult Launch()
{
    return Redirect("Updater:");
}

它在我的机器上运行.exe文件。但是我想在之后将我的网页重定向到主页。哪个应该是这样的;

第二个例子:

public IActionResult Launch()
{
    Redirect("Updater:"); // launch my application

    return View("Index"); // and return to homepage
}

或在我看来像这样;

第三个例子:

<a href1="@($"ETravelerUpdater:")" href2="@Url.Action("Index", "Home")">
    <img data-src="holder.js/100px280/thumb?theme=vine">
</a>

有一种简单的方法吗?

编辑:第二个和第三个示例中显示的代码无法正常工作,只能说明我要完成的工作。

2 个答案:

答案 0 :(得分:1)

在没有看到Updater:动作的情况下,我对它的运作方式做了一些假设。无论哪种方式,这应该让您了解如何使用来自客户端的javascript处理多个重定向。

<script>
    function myFunction() {
        window.open('MyUpdaterLink.com', '_blank'); // opens in new tab
        window.location.href = "MyIndexLink.com"; // opens in current window
    }
</script>

<button onclick="myFunction()">
    <img data-src="holder.js/100px280/thumb?theme=vine">
</button>

答案 1 :(得分:0)

David Lee's answer的附加内容我想提供一个答案,允许用户使用javascript相同标签上导航到多个网址;

@model LaunchViewModel
<a href="javascript:Launch('ETravelerUpdater:|@Model.EmployeeName|SalesQuotes|@Model.AccessLevel')">
    <img data-src="holder.js/100px280/thumb?theme=sky&text=Sales%20Quotes" alt="Card image cap">
</a>

<script>
    async function Launch(url) {
        window.location.href = url;
        await sleep(1000);
        window.location.href = "./"; 
    }

    function sleep(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }
</script>

点击锚标记后,用户将导航到url参数,等待一秒后,用户将导航到第二个网址,在这种情况下是主页。