2017-08-30 105 views
0

使用Custom URL Protocol我爲自己設置了一個名爲更新器的url,這意味着當我調用下面的控制器時;Asp.net(核心) - 導航到多個網址

第一個例子:

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> 

是否有一個簡單的方法來做到這一點?

編輯:在第二個和第三個例子中顯示的代碼不起作用,它只是在那裏給出一個想法,我試圖完成。

+0

爲什麼不在你的'Launch'動作中加入'Update:'代碼? –

+0

@DavidLee哦,我明白你的意思,如果我按照你的建議去做,代碼將在服務器上運行。但是,如果安裝.exe,目前代碼將在客戶端計算機上運行。 – 0014

+1

不知道我是否瞭解您的案例,但您可以做的是在您的應用程序或您的主頁上重定向客戶端到您的網址。你可以用javascript或jquery來做到這一點。例如,您可以在加載索引頁時運行此操作。 'window.location.href =「MyUpdaterLink.com」;' –

回答

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> 
0

附加David Lee's answer我想提供一個答案,將允許用戶導航到多個URL因此使用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參數,並等待一秒鐘後,用戶會轉到在這種情況下,第二url主頁。