safetyOtter
safetyOtter

Reputation: 1460

Set starting route in a visual studio blazor project

I'm working on a server side 3.0.100 blazor project in VS2019.

I have several pages. I would like it if while I was debugging i could start a non-default route/page for debugging purposes.

What I've tried on the project properties debug tab:

1) Setting the Launch browser relative path. If i set this, to say "equipmentlist", the app starts at localhost:44325/equipmentlist but displays the root route. If i then navigate to the equipmentlist page, the url changes to localhost:44325/equipmentlist/equipmentlist and the correct content displays.

2) Setting the App URL: this has the same behavior as 1

I'd like to save myself extra clicks every time i click debug.

Edit: The "Launch browser" setting changes the address that displays when the browser launches, but the content displayed is still the default route.

i.e. localhost:44325/equipmentlist/ is displayed in the browser address bar but it still shows the content from the "/" page. I have to navigate to localhost:44325/equipmentlist/equipmentlist to see the content required.

Upvotes: 10

Views: 7905

Answers (3)

I had the same problem and stumbled opon your question. Maybe someone else will and finds here some help or explanation for this:


After some tests it seemed, that IIS Express wasn't able to route proberly. Without using IIS Express, everything was working as intended.

After some tests and searching I could resolve this problem by deleting the .vs folder.


In this folder, you can find the applicationhost.config. This file controls the IIS Express applications for your project.

In it you can find a knote for application. Here is defined, which Application Pool will be used and where the physical files are located. If you change "applicationUrl" in the "launchSettings.json", a new knote will be added and causing this problem. Even if you change "applicationUrl" back, the knote will not disappear!

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

To solve this, simply delete the wrong knote and you should be fine.

Upvotes: 0

agua from mars
agua from mars

Reputation: 17424

You have two way to do it :

The easiest one is to open the project properties and set Launch browser URL in the Debug panel :

enter image description here

This'll update your Properties\launchSettings,json file for you. But you can manually edit it of course.

{
...
  "profiles": {
...
    "Aguacongas.TheIdServer.BlazorApp": {
...
      "launchBrowser": true,
      "launchUrl": "equipmentlist",
...
    }
  }
}

Upvotes: 5

Ryan
Ryan

Reputation: 20116

You need to modify launchSettings.json file under the Properties node of the project to set launchUrl for IIS Express profile, like

"profiles": {
"IIS Express": {
  "commandName": "IISExpress",
  "launchBrowser": true,
  "launchUrl": "equipmentlist",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
},
//...

Upvotes: 12

Related Questions