2017-09-25 84 views
0

我有一個ASP.NET Core web API;這是一個簡單的休息界面。調試asp.net核心API/REST應用程序:更改defauilt路徑

在項目屬性,我有這樣的路徑:

Application Url

,但是當我在調試器啓動,它總是轉到:

http://localhost:58187/api/values 

調試器加載時瀏覽器,在這裏是網址:

data:text/html;charset=utf-8,<head><meta http-equiv="refresh" content="0; url=http://localhost:58187/api/values"/></head><body><style>body{margin:25px;font:16px calibri,'segoe ui'}</style><h3>Chrome script debugging in Visual Studio is enabled</h3><ul><li>Set breakpoints in JavaScript/TypeScript in Visual Studio</li><li>Automatically break on script errors</li><li>Opening developer tools in Chrome stops the script debugging session</li></ul><a href='https://aka.ms/chromedebugging' target='_blank'>Learn more about Chrome debugging in Visual Studio</a><h4><i>Your application is starting...</i></h4></body><!----> 

我可以看到api/values初始Url中的字符串。

如何更改api/values字符串?

回答

2

在Visual Studio啓動設置中配置在運行或調試應用程序時在瀏覽器中打開的默認啓動路徑。這些可以在Properties/launchSettings.json中配置。在該文件中,會出現這樣的部分:

"profiles": { 
    "profileName": { 
    "commandName": "…", 
    "launchBrowser": true, 
    "launchUrl": "api/values", 
    "environmentVariables": { 
     "ASPNETCORE_ENVIRONMENT": "Development" 
    } 
    }, 
} 

可能有多個配置文件,通常至少有一個「IIS快車」和一個具有相同的名稱爲您的應用程序。這些配置文件與您從Visual Studio的調試按鈕(帶有綠色播放圖標的按鈕)下拉菜單相匹配。

正如您從配置中看到的,有一個launchUrl配置,它具有api/values值。這是瀏覽器默認打開的路徑。您可以將其更改爲任何您想讓瀏覽器走到需要的位置。

您還可以創建新的啓動配置文件,以便爲每個主控制器或其他配置文件配置不同的配置文件。當然,您也可以禁用launchBrowser設置,以避免瀏覽器每次打開,允許您自己打開網站(或只保留一個標籤頁)。

相關問題