在 visual studio blazor 项目中设置起始路线
Set starting route in a visual studio blazor project
我正在 VS2019 中的服务器端 3.0.100 blazor 项目上工作。
我有几个页面。如果我在调试时可以启动非默认 route/page 用于调试目的,我会喜欢它。
我在项目属性调试选项卡上尝试过的内容:
1) 设置启动浏览器的相对路径。如果我设置这个,比如 "equipmentlist",应用程序从 localhost:44325/equipmentlist 开始,但显示根路径。如果我然后导航到设备列表页面,url 更改为 localhost:44325/equipmentlist/equipmentlist 并显示正确的内容。
2) 设置应用程序 URL:这与 1
具有相同的行为
我想在每次单击调试时为自己节省额外的点击次数。
编辑:
"Launch browser" 设置更改了浏览器启动时显示的地址,但显示的内容仍然是默认路由。
即localhost:44325/equipmentlist/ 显示在浏览器地址栏中,但它仍然显示来自“/”页面的内容。我必须导航到 localhost:44325/equipmentlist/equipmentlist 才能看到所需的内容。
需要修改项目Properties
节点下的launchSettings.json
文件,为IIS Express
配置文件设置launchUrl
,如
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "equipmentlist",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
//...
你有两种方法:
最简单的方法是打开项目属性并在 Debug 面板中设置 Launch browser URL :
这将为您更新 Properties\launchSettings、json 文件。但是你当然可以手动编辑它。
{
...
"profiles": {
...
"Aguacongas.TheIdServer.BlazorApp": {
...
"launchBrowser": true,
"launchUrl": "equipmentlist",
...
}
}
}
我遇到了同样的问题,偶然发现了你的问题。也许其他人会在这里找到一些帮助或解释:
经过一些测试,IIS Express 似乎无法正确路由。
在不使用 IIS Express 的情况下,一切都按预期工作。
经过一些测试和搜索,我可以通过删除 .vs 文件夹来解决这个问题。
在此文件夹中,您可以找到 applicationhost.config。此文件控制项目的 IIS Express 应用程序。
在里面你可以找到一个应用程序的结。这里定义了将使用哪个应用程序池以及物理文件所在的位置。
如果您更改“launchSettings.json”中的“applicationUrl”,则会添加一个新结并导致此问题。即使你把“applicationUrl”改回来,结也不会消失!
<site name="Webapplication1" id="3">
<application path="/" applicationPool="Webapplication1 AppPool">
<virtualDirectory path="/" physicalPath="C:\source\repos\Webapplication1" />
</application>
<application path="/equipmentlist" applicationPool="equipmentlist AppPool">
<virtualDirectory path="/" physicalPath="C:\source\repos\Webapplication1" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:62461:localhost" />
<binding protocol="https" bindingInformation="*:44381:localhost" />
</bindings>
</site>
要解决此问题,只需删除错误的节点即可。
我正在 VS2019 中的服务器端 3.0.100 blazor 项目上工作。
我有几个页面。如果我在调试时可以启动非默认 route/page 用于调试目的,我会喜欢它。
我在项目属性调试选项卡上尝试过的内容:
1) 设置启动浏览器的相对路径。如果我设置这个,比如 "equipmentlist",应用程序从 localhost:44325/equipmentlist 开始,但显示根路径。如果我然后导航到设备列表页面,url 更改为 localhost:44325/equipmentlist/equipmentlist 并显示正确的内容。
2) 设置应用程序 URL:这与 1
具有相同的行为我想在每次单击调试时为自己节省额外的点击次数。
编辑: "Launch browser" 设置更改了浏览器启动时显示的地址,但显示的内容仍然是默认路由。
即localhost:44325/equipmentlist/ 显示在浏览器地址栏中,但它仍然显示来自“/”页面的内容。我必须导航到 localhost:44325/equipmentlist/equipmentlist 才能看到所需的内容。
需要修改项目Properties
节点下的launchSettings.json
文件,为IIS Express
配置文件设置launchUrl
,如
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "equipmentlist",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
//...
你有两种方法:
最简单的方法是打开项目属性并在 Debug 面板中设置 Launch browser URL :
这将为您更新 Properties\launchSettings、json 文件。但是你当然可以手动编辑它。
{
...
"profiles": {
...
"Aguacongas.TheIdServer.BlazorApp": {
...
"launchBrowser": true,
"launchUrl": "equipmentlist",
...
}
}
}
我遇到了同样的问题,偶然发现了你的问题。也许其他人会在这里找到一些帮助或解释:
经过一些测试,IIS Express 似乎无法正确路由。 在不使用 IIS Express 的情况下,一切都按预期工作。
经过一些测试和搜索,我可以通过删除 .vs 文件夹来解决这个问题。
在此文件夹中,您可以找到 applicationhost.config。此文件控制项目的 IIS Express 应用程序。
在里面你可以找到一个应用程序的结。这里定义了将使用哪个应用程序池以及物理文件所在的位置。 如果您更改“launchSettings.json”中的“applicationUrl”,则会添加一个新结并导致此问题。即使你把“applicationUrl”改回来,结也不会消失!
<site name="Webapplication1" id="3">
<application path="/" applicationPool="Webapplication1 AppPool">
<virtualDirectory path="/" physicalPath="C:\source\repos\Webapplication1" />
</application>
<application path="/equipmentlist" applicationPool="equipmentlist AppPool">
<virtualDirectory path="/" physicalPath="C:\source\repos\Webapplication1" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:62461:localhost" />
<binding protocol="https" bindingInformation="*:44381:localhost" />
</bindings>
</site>
要解决此问题,只需删除错误的节点即可。