How can I change IIS Express port for a site - c#

I want to change the port number on which my website runs while debugging from Visual Studio. I am using Visual Studio 2012, and I am using ASP.NET MVC 4 for my projects I want to change the port. Random port or fixed anyone will work just want to change the port.

To specify a port for a Web application project that uses IIS Express
In Solution Explorer, right-click the name of the application and then select Properties.
Click the Web tab.
In the Servers section, under Use Local IIS Web server, in the Project URL box change the port number.
To the right of the Project URL box, click Create Virtual Directory, and then click OK.
In the File menu, click Save Selected Items.
To verify the change, press CTRL+F5 to run the project.
The new port number appears in the address bar of the browser.
From How to: Specify a Port for the Development Server (archive.org backup here).

Here's a more manual method that works both for Website projects and Web Application projects. (you can't change the project URL from within Visual Studio for Website projects.)
Web Application projects
In Solution Explorer, right-click the project and click Unload Project.
Navigate to the IIS Express ApplicationHost.config file. By default, this file is located in:
%userprofile%\Documents\IISExpress\config
In recent Visual Studio versions and Web Application projects, this file is in the solution folder under [Solution Dir]\.vs\config\applicationhost.config (note the .vs folder is a hidden item)
Open the ApplicationHost.config file in a text editor. In the <sites> section, search for your site's name. In the <bindings> section of your site, you will see an element like this:
<binding protocol="http" bindingInformation="*:56422:localhost" />
Change the port number (56422 in the above example) to anything you want. e.g.:
<binding protocol="http" bindingInformation="*:44444:localhost" />
Bonus: You can even bind to a different host name and do cool things like:
<binding protocol="http" bindingInformation="*:80:mysite.dev" />
and then map mysite.dev to 127.0.0.1 in your hosts file, and then open your website from "http://mysite.dev"
In Solution Explorer, right-click the the project and click Reload Project.
In Solution Explorer, right-click the the project and select Properties.
Select the Web tab.
In the Servers section, under Use Local IIS Web server, in the Project URL box enter a URL to match the hostname and port you entered in the ApplicationHost.config file from before.
To the right of the Project URL box, click Create Virtual Directory. If you see a success message, then you've done the steps correctly.
In the File menu, click Save Selected Items.
Website projects
In Solution Explorer, right-click the project name and then click Remove or Delete; don't worry, this removes the project from your solution, but does not delete the corresponding files on disk.
Follow step 2 from above for Web Application projects.
In Solution Explorer, right-click the solution, select Add, and then select Existing Web Site.... In the Add Existing Web Site dialog box, make sure that the Local IIS tab is selected. Under IIS Express Sites, select the site for which you have changed the port number, then click OK.
Now you can access your website from your new hostname/port.

.Net Core
For those who got here looking for this configuration in .Net core this resides in the Properties\lauchSettings.json. Just edit the port in the property "applicationUrl".
The file should look something like this:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:53950/", //Here
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "index.html",
"environmentVariables": {
"Hosting:Environment": "Development"
},
}
}
}
Or you can use the GUI by double clicking in the "Properties" of your project.
Note: I had to reopen VS to make it work.

Right click on your MVC Project. Go to Properties. Go to the Web tab.
Change the port number in the Project Url. Example. localhost:50645
Changing the bold number, 50645, to anything else will change the port the site runs under.
Press the Create Virtual Directory button to complete the process.
See also: http://msdn.microsoft.com/en-us/library/ms178109.ASPX
Image shows the web tab of an MVC Project

If you just want to change the port because it is already in use. Follow the following steps.
In Visual studio
Right-click on Project Node and select Unload Project
Right-click on Project Node and Edit .csproj file.
Search for the following tags and remove them
<DevelopmentServerPort>62140</DevelopmentServerPort>
<DevelopmentServerVPath></DevelopmentServerVPath>
<IISUrl>http://localhost:62116/</IISUrl>
press Ctrl + S to save the document
Right-click on Project Node and load Project
It will work by selecting another port randomly.
For further information. please click

Another fix for those who have IIS Installed:
Create a path on the IIS Server, and allocate your website/app there.
Go to propieties of the solution of the explorer, then in front of using the iisexpress from visual studio, make that vs uses your personal own IIS.

You can first start IIS express from command line and give it a port with /port:port-number
see other options.

If we are talking about a WebSite, not web app, my issue was that the actual .sln folder was somewhere else than the website, and I had not noticed. Look for the .sln path and then for the .vs (hidden) folder there.

For old Website projects you will need to modify port in solution file, find section similar to below and change "VWDPort" property
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "My Website", "My Website\", "{871AF49A-F0D6-4B10-A80D-652E2411EEF3}"
ProjectSection(WebsiteProperties) = preProject
SccProjectName = "<Project Location In Database>"
SccAuxPath = "<Source Control Database>"
SccLocalPath = "<Local Binding Root of Project>"
SccProvider = "Mercurial Source Control Package"
TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.7.2"
ProjectReferences = "{41176de9-0c21-4da1-8532-4453c9cbe289}|My.CommonLibrary.dll;{f1fda4e5-0233-458e-97b8-381bdb38a777}|My.Ajax.dll;{e756176c-9cd1-4dac-9b2d-9162b7554c70}|My.WEB.API.Domain.dll;{7A94A6C8-595B-43CF-9516-48FF4D8B8292}|My.WEB.API.Common.dll;{790654F2-7339-472C-9A79-9E36837571A0}|My.Api.dll;{25aa245b-89d9-4d0c-808d-e1817eded876}|My.WEB.API.DAL.dll;{cc43d973-6848-4842-aa13-7751e655966d}|My.WEB.API.BLL.dll;{41591398-b5a7-4207-9972-5bcd693a9552}|My.FacialRecognition.dll;"
Debug.AspNetCompiler.VirtualPath = "/My Website"
Debug.AspNetCompiler.PhysicalPath = "My Website\"
Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\My Website\"
Debug.AspNetCompiler.Updateable = "true"
Debug.AspNetCompiler.ForceOverwrite = "true"
Debug.AspNetCompiler.FixedNames = "false"
Debug.AspNetCompiler.Debug = "True"
Release.AspNetCompiler.VirtualPath = "/My Website"
Release.AspNetCompiler.PhysicalPath = "My Website\"
Release.AspNetCompiler.TargetPath = "PrecompiledWeb\My Website\"
Release.AspNetCompiler.Updateable = "true"
Release.AspNetCompiler.ForceOverwrite = "true"
Release.AspNetCompiler.FixedNames = "false"
Release.AspNetCompiler.Debug = "False"
VWDPort = "3883"
SlnRelativePath = "My Website\"
EndProjectSection
ProjectSection(ProjectDependencies) = postProject
{C3A75E14-1354-47CA-8FD6-0CADB80F1652} = {C3A75E14-1354-47CA-8FD6-0CADB80F1652}
EndProjectSection
EndProject

For web projects:
Close Visual Studio
Open [projectName].sln in solution root directory using a text editor (like sublime)
Search your current port number you will find 5 instances
Replace them with new port number and save file
Delete .vs file in the solution root directory
Start visual studio then the .vs file will be created again. run the web project it will start with new port

Edit .sln file using an editor like notepad.
Replace All Ports With New Port.

I'd the same issue on a WCF project on VS2017. When I debug, it gives errors like not able to get meta data, but it turns out the port was used by other process. I got some idea from here, and finally figure out where the port was kept. There are 2 places:
1. C:...to your solution folder....vs\config\applicationhost.config. Inside, you can find the site that you debug. Under , remove the that has port issue.
2. C:...to your project folder...\, you will see a file with ProjectName.csproj.user. Remove this file.
So, close the solution, remove the and the user file mentioned above, then reopen the solution, VS will find another suitable port for the site.

I'm using VS 2019.
if your solution has more than one project / class libraries etc, then you may not see the Web tab when clicking on Solution explorer properties.
Clicking on the MVC project and then checking properties will reveal the web tab where you can change the port.

Deploy your application in the IIS with the default port. Try to debug it using visual studio. It's a good practice. If you use visual studio, it will keep changing the port number most of the time. So better deploy the application in the IIS first and Open the same in visual studio and Debug it.

Related

Unable to start program. [VALUE].dll is not a valid Win32 application error in Visual Studio 2017

I have developed an C#, ASP.NET web application in a Windows 7 machine using Visual Studio 2012. Now i had imported the entire project into VS 2017 running on windows 10 machine, and when i try to enter the debugging mode to analyze my code it shows the following error:
I guess the project configurations are conflicting hence it throws this error.
Any suggestions??
The same error happens when Visual Studio solution has selected the wrong Startup Project. The bold project is the designated startup project.
Go to the Solution Explorer > Right click on the correct project and select "Set as StartUp Project" in the context menu.
I also got this error. I ultimately got to know that I was not selecting .sln file.
In VS, you should select .sln file and it automatically loads the complete project structrue is what I learnt.
Selecting .sln file worked for me
These errors are mostly because you are not selecting the .sln or solution file. In your solution explorer tree, double click the solution file and then build and run.
This runs contrary to a users intuition that simply opening a file and running it would work. Consider it a poor user interface. Jet Brains Rider, for instance, does not have this issue.
Change Targeting Platforms with the Configuration Manager and Build the project then try to debug it.I hope this will help you.
Don't export the project folder. upload the .sln file.
It will work.
DLLs cannot be ran/debugged directly. You have to specify host application in the
Configuration Properties>Debugging>Command and then let it load the DLL by itself.
You will most likely need to copy the DLL to the directory searchable by the host application e.g. its root or ./plugins folder.
In the Configuration Properties>Build Events>Post-Build Event>Command Line simply enter something like:
copy "$(TargetPath)" "$(HOST_APP)\plugins"
The Startup Item needs to be a .exe file. It's looking at BusinessLayer.dll because BusinessLayer is currently the Startup Project.
First, build the solution. Then, set the Solution Explorer to folder view and find the .exe in one of you project's /bin folders. Right click on it and set it to the Startup Item.
Finally, click the play button in Visual Studio top bar.
EDIT: Basically the same as Thomas' answer, but I'm pointing out that the "correct project" is the one with the .exe file. I would have commented on his answer, but I have less than 50 rep right now.

This site can't be reached error

I have an asp.net MVC project developed in VS2015. Now I try to run it in VS2017 and get an error:
This site can't be reached.
What can I do with this trouble?
In my case IIS Express is not allowing https so I needed to do this:
open cmd as admin
cd C:\Program Files (x86)\IIS Express
IisExpressAdminCmd.exe setupsslUrl -url:https://localhost:portnumber/ -UseSelfSigned
Here is what I did: I went to the project tab -> properties -> Web then clicked the create virtual directory and everything started working back normal.
Try this and it should work:
1-Go to your project folder and open .vs folder (keep your check hidden item-box checked as this folder may be hidden sometimes)
2- in .vs folder - open config
3- see that applicationhost config file there? Delete that thing.(Do not worry it will regenerate automatically once you recompile the project.)
link:
localhost refused to connect Error in visual studio
In my case, it was not the application but what I was submitting. My form contained a file I was uploading and when I hit submit I would get that error. Turns out the file couldn't be uploaded because the file was in use. I just closed the file I was trying to attach and it worked.
For the VS 2019, If you set SSL enabled for your project, there are two URLs create for your project (URL and SSL URL).
To fix this issue Go to project properties => Web: update the Project Url, Create virtual Directory and save.
I had the same problem, I noticed that in certificate manager => personal, the localhost certificate is missing
I copied that from certificate manager => TrustedRoot and the problem solved
altho it might be caused by other problems
Try this...
open command prompt Run as Administrator
type ipconfig /flushdns --
Message should appear: "Successfully flushed the DNS Resolver Chache".
after that type netsh winsock reset --
Message should be appear: "Successfully reset the winsock catalog. you must restart the computer in order to complete the reset."
Then restart your machine.
Here's what I did. Right-click on the project and go to properties. Under the Debug tab uncheck and check Enable SSL. It will create a random url with port. Copy and paste the generated URL in the App URL. It worked for me fine there after.
Follow the below steps
Right-click on the project and go to properties
Under the Debug tab uncheck Enable SSL
matendie answer working for me,
open cmd as admin
cd C:\Program Files (x86)\IIS Express
IisExpressAdminCmd.exe setupsslUrl -url:https://localhost:portnumber/ -UseSelfSigned

Visual studio 2013: Manually specify localhost port no. for website project

I am working on an angular project in visual studio.
I have created a Blank solution visual studio then added the existing website.
Open VS>>New Project>>Blank Solution>>Right click solution>>Add existing web site>>select Folder>>F5
Due to some reason I have to run the website on the localhost:8080 but the visual studio is setting the port itself.
How to change the running port to 8080
I have googled a lot but the only solutions I found is for ASP.net.
like
stackover flow,
microsoft docs
Alt+Enter is opening this property window
You can change the port in the Properties page of the project.
Right click the project and go to Properties or Alt + Enter.
Properties > Web.
Under Servers section, select "Specific Port" and provide one. :)
You can't change the project URL from within Visual Studio for Website projects.
There are two working methods for me, Posting this answer after testing.
First Option
Web Site Projects don't have a .*proj file to store settings instead, the settings are set in the solution file. In VS2013, the settings look something like this:
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "TestWebSite", "http://localhost:56422", "{401397AC-86F6-4661-A71B-67B4F8A3A92F}"
ProjectSection(WebsiteProperties) = preProject
UseIISExpress = "true"
TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.5"
...
SlnRelativePath = "..\..\WebSites\WebSite1\"
DefaultWebSiteLanguage = "Visual Basic"
EndProjectSection
EndProject
Because the project is identified by the URL (including port), there isn't a way in the Visual studio UI to change this. You should be able to modify the solution file though, and it should work.
Note: In your case to set the port to 8080 you must open visual studio in Run as Administrator mode. You MUST run Visual Studio as an administrator in order to open websites with a port less than 1000
Credit of this option goes to Jimmy and original answer is here
Second Option
To specify a port for any web site project that uses IIS Express:
First Add the existing website and run it once. So that it gets assigned in the IIS sites list.
In project go to Solution Explorer, right-click the project name and then click Remove or Delete; don't worry, this removes the project from your solution, but does not delete the corresponding files on disk.
Navigate to the IIS Express ApplicationHost.config file. By default, this file is located in:
%systemdrive%\Users\<YourWindowsUsername>\Documents\IISExpress\config
Open the ApplicationHost.config file in a text editor. In the <sites> section, search for your site's name. In the <bindings> section of your site, you will see an element like this:
<binding protocol="http" bindingInformation="*:56422:localhost" />
Change the port number (56422 in the above example) to anything you want. e.g.:
<binding protocol="http" bindingInformation="*:8080:localhost" />
and then map mysite.dev to 127.0.0.1 in your hosts file, and then open your website from "http://mysite.dev"; but that's outside the scope of this answer so I won't go into any more details)
In Solution Explorer, right-click the solution, select Add, and then select Existing Web Site.... In the Add Existing Web Site dialog box, make sure that the Local IIS tab is selected. Under IIS Express Sites, select the site for which you have changed the port number, then click OK.
Now you can access your website from your new hostname/port.
Credit of this option goes to Saeb Amini and the original answer is here

Changing project port number in Visual Studio 2013

How can I change the project port number in Visual Studio 2013 ?
I'm using ASP.Net and I need to change the port number while debugging in Visual Studio 2013.
There are two project types in VS for ASP.NET projects:
Web Application Projects (which notably have a .csproj or .vbproj file to store these settings) have a Properties node under the project. On the Web tab, you can configure the Project URL (assuming IIS Express or IIS) to use whatever port you want, and just click the Create Virtual Directory button. These settings are saved to the project file:
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<DevelopmentServerPort>10531</DevelopmentServerPort>
...
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
Web Site Projects are different. They don't have a .*proj file to store settings in; instead, the settings are set in the solution file. In VS2013, the settings look something like this:
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "WebSite1(1)", "http://localhost:10528", "{401397AC-86F6-4661-A71B-67B4F8A3A92F}"
ProjectSection(WebsiteProperties) = preProject
UseIISExpress = "true"
TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.5"
...
SlnRelativePath = "..\..\WebSites\WebSite1\"
DefaultWebSiteLanguage = "Visual Basic"
EndProjectSection
EndProject
Because the project is identified by the URL (including port), there isn't a way in the VS UI to change this. You should be able to modify the solution file though, and it should work.
Right click the web application and select "properties"
There should be a 'Web' tab where http://localhost:XXXXX is specified - change the port number there and this will modify the configuration to use your new port number.
I usually start at 10000 and increment by 1 for each web app, to attempt to steer well clear of other applications and port numbers.
This has proved to be elusive for me (WebSite Project) until I figured out the following procedure, which combines the solution provided by #Jimmy, with the added step of checking out the solution from Source Control
Steps: (if using VS2013+ with website project and SourceControl)
Check out the Solution file only (from sourceControl) (this can be tricky. the easiest way to do this is to make a small change in the Solution file properties/settings and then undo if necessary)
Locate the solution file (e.g. solution.sln) in exploer, and open in text editor.
Locate the entry: VWDPort = ...... and change to desired port: (example: "60000" - depends on your IISExpress Settings)
save the change (will prompt to reload solution)
Well, I simply could not find this (for me) mythical "Use dynamic ports" option. I have post screenshots.
On a more constructive note, I believe that the port numbers are to be found in the solution file AND CRUCIALLY cross referenced against the IIS Express config file
C:\Users\<username>\Documents\IISExpress\config\applicationhost.config
I tried editing the port number in just the solution file but strange things happened. I propose (no time yet) that it needs a consistent edit across both the solution file and the config file.
Open Solution file (.sln) in Editable mode (Notepad or notepad++ or any other tool)
Find tag name VMDPort and update it to your desired port.
see below snap.
To specify a port for the ASP.NET Development Server
In Solution Explorer, click the name of the application.
In the Properties pane, click the down-arrow beside Use dynamic ports
and select False from the dropdown list.
This will enable editing of the Port number property.
In the Properties pane, click the text box beside Port number and
type in a port number. Click outside of the Properties pane. This
saves the property settings.
Each time you run a file-system Web site within Visual Web Developer,
the ASP.NET Development Server will listen on the specified port.
Hope this helps.
The Visual Studio Development Server option applies only when you are
running (testing) the Web project in Visual Studio. Production Web
applications always run under IIS.
To specify the Web server for a Web site project
In Solution Explorer, right-click the name of the Web site project for which you want to specify a Web server, and then click Property
Pages.
In the Property Pages dialog box, click the Start Options tab.
Under Server, click Use custom server.
In the Base URL box, type the URL that Visual Studio should start when running the current project.
Note: If you specify the URL of a remote server (for example, an IIS Web application on another computer), be sure that the remote server is running at least the .NET Framework version 2.0.
To specify the Web server for a Web application project
In Solution Explorer, right-click the name of the Web application project for which you want to specify a Web server, and then click
Properties.
In the Properties window, click the Web tab.
Under Servers, click Use Visual Studio Development Server or Use Local IIS Web server or Use Custom Web server.
If you clicked Local IIS Web server or Use Custom Web Server, in the Base URL box, type the URL that Visual Studio should start when
running the current project.
Note: If you clicked Use Custom Web Server and specify the URL of a remote server (for example, an IIS Web application on another computer), be sure that the remote server is running at least the .NET Framework version 2.0.
(Source: https://msdn.microsoft.com/en-us/library/ms178108.aspx)
Steps to resolve this:
Open the solution file.
Find the Port tag against your project name.
Assign any different port as current.
Right click on your project and select Property Pages.
Click on Start Options tab and checked Start URL: option.
Assign the start URL in front of Start URL option like: localhost:8080/login.aspx
This is the only solution that worked for me after trying several of those above. Switch to your c:\users folder and search for .sln and then remove all .sln files that have your project name. Then restart your computer and rebuild the solution (F5) and it worked!

How to get a Web Service to use a Fixed Port Number When Using the Visual Studio Development Server?

I have an asp.net website and a windows form application.
My Webservice's Location is : http://localhost:12312/MyWebSiteFolder/WSFile.asmx
Problem is : the port number keeps changing, if I reopen the solution, its going to change to something else:
http://localhost:11122/MyWebSiteFolder/WSFile.asmx
Is there a way so I won't have to update the location of the file in my windows form application everytime I reopen the website's solution?
(assuming Visual Studio 2010)
Under the Web tab of the properties for the project, change the "Auto-assign Port" option to "Specific port" and enter the port you want to always use.
Alternately, if possible, you can choose the option to use your local IIS server.
Update:
If you're using a "Web Site" project instead of "Web Application," the setting is located in the properties window of the project instead of the properties dialog. Note the "Use dynamic ports" option here:
How does your web application look on the Solution explorer - does it show
<drive>:\<some directory>
or
does it show the name of your web application with no path.
or
does it show http:/// <something>
In case 1 you should be able to see properties. But you wont get it for the rest

Categories

Resources