【发布时间】:2019-09-12 18:23:51
【问题描述】:
保存正在进行的工作
尝试从 Visual Studio 2019(或 Visual Studio 2017 或 Visual Studio 2015)运行网站时,出现错误:
-
Visual Studio 2015:
无法连接到已配置的开发 Web 服务器。
-
Visual Studio 2017:
无法连接到已配置的开发 Web 服务器。
IIS Express 的输出:
正在启动 IIS Express...
在应用程序“/”中成功为站点“WebSite3”注册 URL“http://localhost:59392/”
已完成网站“WebSite3”的注册
IIS Express 正在运行。 -
Visual Studio 2019:
无法连接到已配置的开发 Web 服务器。
IIS Express 的输出: 启动 IIS Express ... 成功为站点“WebSite3”应用程序“/”注册 URL“http://localhost:59392/” 已完成网站“WebSite3”的注册 IIS Express 正在运行。
IISExpress 正在实际上正在运行和监听,但实际上没有任何效果:
你有什么尝试 - everything
我尝试过的事情(来自 Stackoverflow 上的所有其他问题):
netsh http add urlacl url=http://localhost:56997/ user=everyone- 以管理员身份运行 Visual Studio
- 重启 Windows
- 删除隐藏的
.vs文件夹 - 从不同的文件夹运行网站
- 关闭 Windows 防火墙
- 更改网站的端口
- 更改网站的端口并点击创建虚拟目录
- 从我的 Documents 文件夹中删除 IISExpress 文件夹
- 全新安装 Visual Studio(我安装了 2019)
你可以看到 IISExpress 创建了一个监听套接字,并且 IISExpress 通知区域图标显示 IISExpress 认为该网站正在运行:
但它不会响应任何内容:
Bonus Chatter - Windows 内置内核模式 Web 服务器
IISExpress.exe 本身不会打开侦听套接字。
Windows 带有一个内置的内核模式迷你网络服务器:http.sys。您和 IISExpress.exe 通过调用以下方式使用此 Web 网络服务器:
//Initialize HTTP Server APIs
HttpInitialize(HTTPAPI_VERSION_1_0, HTTP_INITIALIZE_SERVER, null);
//Create a Request Queue
HANDLE requestQueue;
HttpCreateHttpHandle(ref requestQueue, 0);
/*
Add URIs to listen on. We call HttpAddUrl for each URI.
The URI is a fully qualified URI and must include the terminating (/) character.
The IANA port numbers state ports 49152-65535 are for dynamic/private purposes.
HttpAddUrl for localhost on a port >= 49152 works fine for non-admins.
*/
String url = "http://localhost:80/"; //Ports 1-1024 require administrator access
/*
You can use netsh to modify the HttpServer api ACL to grant everyone acces s to port 80:
netsh http add urlacl url=http://localhost:80/ user=EVERYONE listen=yes delegate=no
But it is useful to note that WCF already has an "Everyone Allow" entry for port 80,
as long as your URL starts with "/Temporary_Listen_Addresses/"
WCF creates URLs of the form:
http://+80/Temporary_Listen_Address/[random guid]/
*/
url = "http://+:80/Temporary_Listen_Addresses/{87CB7BDF-A52D-4496-AA1D-B6F60AC2841E}/"; //WCF style url
//Or we can just use one above 1024
url = "http://localhost:2113/";
将 URL 添加到您的请求队列中
//Add the url to our request queue
ret = HttpAddUrl(requestQueue, url, null);
然后你设置一个循环来处理请求:
while (true)
{
THTTP_REQUEST_ID requestID;
Int32 requestBufferLength = sizeof(THTTP_REQUEST) + 16384;
PHTTP_REQUEST request = GetMemory(requestBufferLength );
DWORD bytesRead;
ULONG res = HttpReceiveHttpRequest(requestQueue,
requestId, // Req ID
0, // Flags
request, // HTTP request buffer
requestBufferLength,// req buffer length
ref bytesRead, // bytes received
null // LPOVERLAPPED
);
if (res == NO_ERROR)
{
res = SendHttpResponse(requestQueue, request, 451, "Totally not NSL", "I don't know what you mean ;)");
if (res <> NO_ERROR)
break;
// Reset the Request ID to handle the next request.
requestID = 0;
}
else if (res == ERROR_MORE_DATA)
{
/*
The input buffer was too small to hold the request headers.
Increase the buffer size and call the API again.
When calling the API again, handle the request that failed by passing a RequestID.
This RequestID is read from the old buffer.
*/
requestId = request.RequestId;
//Free the old buffer and allocate a new buffer.
requestBufferLength = bytesRead;
FreeMem(request);
request = GetMemory(requestBufferLength);
}
else if ((result == ERROR_CONNECTION_INVALID) and (requestID <> 0))
{
/*
The TCP connection was corrupted by the peer when attempting to handle a request with more buffer.
Continue to the next request.
*/
//Got invalid connection error
requestID := 0;
}
else
{
// Other unhandled error; stopping processing requests
break;
}
}
这完全是为了解释为什么是 System 正在监听,而不是 IISExpress.exe。
如果您阅读 cmets,您会注意到为什么尝试执行 netsh http add urlacl 主要是货物崇拜编程;超过 1024 的端口不需要添加权限。
相关问题
- How to solve “Microsoft Visual Studio (VS)” error “Unable to connect to the configured development Web server”(大家链接的主问题)
- Unable to connect to configured development server (没有回答)
- Unable to connect to the configured development web sever (以管理员身份运行)
- Create SDDL failed, Error: 1332 (如果您运行的是西班牙语 Windows)
- unable to connect to the configured development web server
- Unable to launch the configured Visual Studio development web server (从头开始创建一个新项目)
- Unable to connect to the server Web development(尝试使用已经不存在的WebDev.WebServer.exe)
- VS2012 ASP.Net error message unable to connect to the configured development web server (关闭防火墙)
- unable to launch the configured development web server (重新安装 Visual Studio)
- unable to connect to the configured development web server in c# project (创建一个新项目)
- Microsoft Visual Studio 2015 Community - Unable to connect to the configured development Web server' error when trying to build website (重新安装 Windows 10)
- VS 2008 "Unable to connect to the ASP.NET Development Server" (更改端口)
- Unable to connect the configured development Web server Visual Studio 2013 (删除 Documents 中的 IISExpress 文件夹)
- Web Site Administration Tool: Unable to connect to SQL Server database (using SQL Server Development Edition) (aspnet_regsql.exe;用于在 SQL Server 数据库中创建用户表 - 货物崇拜编程任何人?)
- Unable to connect to web server (没有答案)
- Unable to start debugging on the web server. Unable to connect to the webserver (重置 IIS;这不适用,因为我没有将 IIS 功能添加到 Windows - VS 提供了它)
- Unable to connect to ASP.Net Development Server issue (WebDev 服务器又名 Cassini;不再存在)
- Unable to connect to Visual Studio's Localhost Web Server (尽量不要使用 IISExpress - 显然我不会这样做)
【问题讨论】:
-
我读到这个:最后,有人用所有适当的信息问了这个问题,我将向下滚动,看看实际的解决方案是什么......该死的。如果你有运气解决这个问题,我很想知道它是什么?
标签: visual-studio-2015 visual-studio-2017 visual-studio-2019