为什么以及如何修复?IIS Express“指定的端口正在使用中" [英] Why and how to fix? IIS Express "The specified port is in use"
问题描述
我们知道在 Visual Studio 中为 Web 应用程序分配了一个随机端口号.它在我的办公室桌面上运行良好.但是当我将代码拉到我的笔记本电脑上(来自 VisualStudio.com)并运行 Web 应用程序时.我收到一条消息,说
We know a random port number is assigned to a web application in Visual Studio. It works fine in my office desktop. But when I pull the code onto my laptop (from VisualStudio.com) and run the web app. I got a message, saying,
端口 10360 已被另一个应用程序使用.
Port 10360 is already being used by another application.
- 尝试切换到 10360 和 1024 以上的端口.
- 停止使用端口 10360 的应用程序.
<小时>
我可以使用 Recommendation #1
修复它,方法是将端口更改为 13333 之类的其他端口.但我很好奇端口 10360 发生了什么.如何检查哪个应用程序正在使用端口 10360?如何停止该应用程序?
I can fix it using Recommendation #1
by changing the port into something else like 13333. But I am very curious what happened to port 10360. How can I check what application is using port 10360? How can I stop that application?
推荐答案
我在 Windows 10 上运行 Visual Studio 2019 时遇到了类似的问题.一些对其他人有效的解决方案似乎包括:
I had a similar issue running Visual Studio 2019 on Windows 10. Some solutions that worked for others seemed to include:
- 更改应用程序端口号.
- 让 Visual Studio 在每次应用程序启动时自动分配一个端口号.
- 重启 Visual Studio
- 重新启动计算机.
不幸的是,这些解决方案都不适合我,分配另一个端口号确实有效,但不是一个可接受的解决方案,因为我的应用程序在指定端口上运行很重要.
Unfortunately, none of these solutions worked for me, assigning another port number did work but was not an acceptable solution as it was important for my application to run on a specified port.
解决方案
首先我运行命令:
netsh http add iplisten ipaddress=::
来自提升的命令行进程.这解决了最初的错误,当尝试运行应用程序时,我不再收到正在使用的端口"错误,相反,我现在收到一个错误,指出应用程序无法绑定到端口,因为需要管理权限.(虽然我以管理员身份运行 Visual Studio)
from an elevated command-line process. This solved the initial error, when attempting to run the application I no longer got the "port in use" error, instead, I now got an error stating the application was unable to bind to the port because administrative privileges were required. (although I was running Visual Studio as administrator)
第二个错误是由 Hyper-V 将端口添加到端口排除范围引起的,我的应用程序使用的端口在这些排除范围之一中.您可以通过运行以下命令来查看这些端口:netsh interface ipv4 show excludeportrange protocol=tcp
The second error was caused by Hyper-V that adds ports to the Port Exclusion Range, the port my application uses was in one of these exclusion ranges.
You can view these ports by running the following command: netsh interface ipv4 show excludedportrange protocol=tcp
要解决第二个错误:
- 禁用 Hyper-V:控制面板 -> 程序和功能 -> 打开或关闭 Windows 功能.取消Hyper-V
- 重新启动计算机.
- 将您使用的端口添加到端口排除范围:
netsh int ipv4 add excludeportrange protocol=tcp startport=50403 numberofports=1 store=persistent
- 重新启用 Hyper-V
- 重启电脑
从这里一切正常.
这篇关于为什么以及如何修复?IIS Express“指定的端口正在使用中"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!