简体   繁体   English

设置本地主机端口固定/静态以在vs2015中进行项目调试

[英]Set localhost port fixed/static for project debugging in vs2015

l am using Asp.Net Maker 2016 for generating my project. 我正在使用Asp.Net Maker 2016生成我的项目。 So, l browse my project via vs2015. 因此,我通过vs2015浏览我的项目。 The problem is after I generate my project from Asp.Net Maker tool and open it in vs2015, the URL of my project is changed. 问题是我从Asp.Net Maker工具生成项目并在vs2015中将其打开后,项目的URL已更改。

something like : 就像是 :

http://localhost:51624/ADD

I want to set the port fixed not dynamic so, how I can do this in vs2015 or Asp.Net 2016 Maker tool? 我想将端口设置为非动态固定,因此如何在vs2015或Asp.Net 2016 Maker工具中做到这一点?

Visual Studio uses IIS Express to run Web Projects . Visual Studio使用IIS Express运行Web项目 When a project is run first time IISExpress creates an entry to applicationhost.config file for the project and assigns a random port to it. 首次运行项目时, IISExpress会为该项目的applicationhost.config文件创建一个条目,并为其分配一个随机端口。 The file is located at - %userprofile%\\Documents\\IISExpress\\config folder. 该文件位于- %userprofile%\\Documents\\IISExpress\\config文件夹中。

Project entries in the file looks like this - 文件中的项目条目如下所示-

<site name="ProjectName" id="5">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="d:\physical path" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:59302:localhost" />
    </bindings>
</site>

Notice the bindingInformation="*:59302:localhost" in the above section. 请注意上一节中的bindingInformation="*:59302:localhost" Here the port number is 59302 . 这里的端口号是59302 You can change this port number to anything you like and next time Visual Studio runs the project it will use your assigned port number. 您可以将此端口号更改为所需的任何名称, Visual Studio下次运行该项目时,它将使用您分配的端口号。

Its best to close all instances of VS and also confirm that IISExpress is not running before changing the file. 最好关闭VS的所有实例,并在更改文件之前确认IISExpress没有运行。 Also, keep a backup of the file beforehand just in case. 另外,为防万一,请事先备份文件。

The port you assign also needs to be free. 您分配的端口也必须是空闲的。 ie no other application should be using the port. 即没有其他应用程序应使用该端口。 Else Visual Studio will fail to run the application. 其他Visual Studio将无法运行该应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM