Home > OS >  Stop Visual Studio launching to selected .cshtml razor file (makes no sense)
Stop Visual Studio launching to selected .cshtml razor file (makes no sense)

Time:09-29

If I have an MVC/razor .cshtml file open and hit F5 to run my app, it launches with the .cshtml file in the URL, which makes absolutely no sense because it is an MVC app which has routing that has nothing to do with the .cshtml file path.

Obviously I can make sure a .cs file is open before I hit F5 (but I never remember to do that the first few times), or I can edit the URL back to the root, but this interrupts my workflow...enough that I feel the need to ask about it on stackoverflow.

Can we disable this, force it to always launch the root url?

(I have the same problem with .html template files, which also have no meaning on their own)

[Microsoft Visual Studio Community 2022 (64-bit) - Version 17.3.4]

CodePudding user response:

If you right-click your project, then select Properties, then scroll for an eternity to something like "Debug settings", then look for a blue link titled something like "Startup configuration", then add some bogus URL ("/") and click OK, you never have to enter that horrible UI ever again.

There will be a file generated Properties\launchSettings.json, from where you can configure the URL that will be launched from then on when you press F5.

CodePudding user response:

The answer seems so obvious now that I found it - just specify the start URL in project properties.

As to why it tries to open a non-sensical MVC file I can only assume the default "Current Page" start action is residue from simpler pure HTML/ASP projects that do not have routing/code-behind, and not enough of a problem to have been remedied.

enter image description here

  • Related