Visual Studio 2017 / IIS Express:无法连接到已配置的开发Web服务器

Ian*_*oyd 9 visual-studio-2015 visual-studio-2017 visual-studio-2019

保存进行中的工作

尝试从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 实际上跑,听,但没有任何实际工作:

在此处输入图片说明

您尝试了什么- 一切

我尝试过的事情(来自Stackoverflow上的所有其他问题):

  • netsh http add urlacl url=http://localhost:56997/ user=everyone
  • 以管理员身份运行Visual Studio
  • 重新启动Windows
  • 删除隐藏的.vs文件夹
  • 从其他文件夹运行网站
  • 关闭Windows防火墙
  • 改变端口的Web网点
  • 更改网站的端口,然后单击创建虚拟目录
  • 从我的文档文件夹中删除IISExpress文件夹
  • 全新安装Visual Studio(我已安装2019)

您可以看到IISExpress正在创建侦听套接字,并且IISExpress通知区域图标显示IISExpress认为该网站正在运行:

在此处输入图片说明

但它什么都不会回应:

在此处输入图片说明

Bonus Chatter-Windows内置内核模式Web服务器

IISExpress.exe本身不会打开侦听套接字。

Windows带有内置的内核模式微型Web服务器:http.sys。您和IISExpress.exe通过以下方式使用此Web 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/";
Run Code Online (Sandbox Code Playgroud)

将URL添加到您的请求队列

//Add the url to our request queue    
ret = HttpAddUrl(requestQueue, url, null);
Run Code Online (Sandbox Code Playgroud)

然后设置一个循环来处理请求:

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;
   }      
}
Run Code Online (Sandbox Code Playgroud)

这完全是为了解释为什么是System在监听,而不是IISExpress.exe

而且,如果您阅读了注释,您会注意到为什么尝试执行netsh http add urlacl主要是出于对货物的狂热编程。您不需要为超过1024个的端口添加权限。

相关问题

小智 1

就我而言,我停止了 nod32 smart scurity 中的防火墙,问题就解决了!


归档时间:

查看次数:

2282 次

最近记录:

6 年,7 月 前