Search code examples
asp.netwebformsvisual-studio-2022iis-express

How to change the IIS Express development port on a WebForms project in VS2022


I have a legacy ASP.NET WebForms app I need to get running. When running it in Visual Studio 2022 it uses port 50007 (http://localhost:50007/). That port has been helpfully reserved by Hyper-V and so I get an error (failed to register URL.... 0x80070020) which is basically: access denied to the port.

How do I change the development/debugging port? Googling provides lots of information, mostly about MVC which does not apply here. I have tried deleting the project's .vs folder and the IISExpress folder (in Documents). There is no mention of 50007 in the project folder.

The 50007 persists and I can't run my code.

I could uninstall Hyper-V but that would probably cause carnage elsewhere.

Any suggestions?


Solution

  • Well assuming say a web forms project?

    When you create a project, I think vs just makes up a port.

    But, from vs go

    Project->"project name" properties.

    Then on the web tab, you should see this:

    enter image description here

    So, just enter a new/different port number in above, and hit "Create Virtual directory". Now, say f5 to run/debug, it should use this new port.

    Now, the above assumes we are using a asp.net web site "project".

    That means the above menu is from this option:

    enter image description here

    However, it is possible that you using a asp.net website, and not a web site project (I don't use nor like that option).

    Hence, you "might" then be opening this as a "web site".

    Assuming you using a web site, then you would be using file->open web site (as opposed to file->open project).

    If that is the case, then of course you don't have a project/properties page.

    That being the 2nd possible case?

    Then you have to edit the .sln manually.

    So, open the folder location (you can right click on the project and choose "Open Folder in File exploer"

    I would after above, close the project - actually CLOSE vs also.

    Ok, now open the .sln file with note pad, and you want to change this line:

    enter image description here

    I don't think it is required to change the other path names, but give this 2nd approach a try.