DarkLink DarkLink - 2 months ago 8
ASP.NET (C#) Question

ASP.NET Use Web.Config to control Port Number to host Web Application Project

I tried to search for this, but didn't found any good explanation.

I am trying to have everything configured on my config files, so it's easier for the user to control the publish and deploy of my application.

In visual studio 2015 I can control the port to host my web application going to:

Right Click Web Application Project > Properties > Web > Project Url

Can this be done by configuration file?

Thank you!

Answer

It can't be done by web.config but you can control it as,

For "Web Application Projects", open ".csproj" file look for the following part.

<WebProjectProperties>
      <UseIIS>True</UseIIS>
      <AutoAssignPort>True</AutoAssignPort>
      <DevelopmentServerPort>21128</DevelopmentServerPort>
      <DevelopmentServerVPath>/</DevelopmentServerVPath>
      <IISUrl>http://localhost:21128/</IISUrl>
      <NTLMAuthentication>False</NTLMAuthentication>
      <UseCustomServer>False</UseCustomServer>
      <CustomServerUrl>
      </CustomServerUrl>
      <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>

Notice the following lines where you can change the port and save it.

<DevelopmentServerPort>21128</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:21128/</IISUrl>

For the "Website projetcs" you have to open ".sln" file and change the port.

I hope the answer helps.

Comments