views:

1984

answers:

5

Hi,

I'm having a visual studio 2008 solution with asp.net 2.0/C# website. When I press F5 to debug, cassini - the development webserver starts properly and hooks it self in the system tray. But there's a problem after this. If cassini starts at say port 4004, the browser looks for port 4002. I will then have to manually change the port in my browser address bar to 4004 to start the website.

I've encountered this problem in VS2005 SP1 as well. This is really killing me by eating lot of my time incurred in manually chaning the port in browser address bar. No help available on this issue on MSDN.

A: 

Is the port on the URL alwas 4002 or is it random also? You can specify a specific port in Visual Studio for a project, but that has always started my browser with the same port that the server started on.

Josh
No it's a dynamic port. Unknowingly the difference always turns out to be of 2.
this. __curious_geek
A: 

Have you tried setting a specific port through the web application settings? Using a fixed port, as opposed to the auto-assign should clean that up.

If not, you can try this as a workaround:

Right click your entry page and select "View in Browser" to start up your web application in Cassini/Web Development Server.

Go to Tools->Attach to Process and find the "WebDev.WebServer.EXE" file or something similar to this. The title should read "ASP.NET Development Server".

This should hook up the debugger to your local development server and allow you do debug as needed.

Dillie-O
I tried fixing up the port in website. When I hit F5 it always says cannot start the server on given port. Then I have to go back and make it dynamic.
this. __curious_geek
Have you tried using a different port than the 4002/4004 you've been dealing with. There could be some lingering conflicts there.
Dillie-O
A: 

I'd suggest looking at the Web debug properties for your web application.

  • With the project open in Visual Studio,
  • Select the root of the web application (the .csproj file),
  • right click and select "Properties" from the context menu.
  • Select the "Web" tab of the properties page set.

Under "Servers", there are 3 options:

  1. Use Visual Studio Development
  2. Server, Use Local IIS Web Server
  3. Use Custom Web Server

Check that "Auto-Assign Port" is selected under "Use Virtual Studio Development Server", and that the Virtual Path is "/".

Changing the settings, saving, building, running, then changing them back to "sensible" values fixed this last time I encountered it.

Alternatively, if you're up for it, you can modify the XML of the .csproj file by hand to the same effect.

Hope this fixes it.

Joel

Rammesses
this does not work.
this. __curious_geek
+2  A: 

Are you running ESET NOD32 Antivirus? Its firewall is likely causing the issue:

ESET NOD32 and Visual Studio Port Numbers

Alex Czarto
Yes, m using it very much.
this. __curious_geek
Follow the instructions in the link above and it will resolve your port issues. You need to add VS to the NOD32 exclusions list.
Alex Czarto
A: 

Thanks! This helped me with Visual Studio (2005) cannot start local webserver, port in use.

Andersson
You should delete your answer and add a comment to the question or accepted answer. As a vote of thanks, you can upvote the selected answer or the question itself.
this. __curious_geek
I added an answer because I do not have enough reputation to add comments. However, if my "answer" still is in the wrong section I have no problems deleting it.
Andersson