简体   繁体   English

无法连接到 web 服务器“IIS Express”

[英]Unable to connect to web server 'IIS Express'

I am using Microsoft Visual Studio 2019 Community preview, version 16.4.0 Preview 1.0.我正在使用 Microsoft Visual Studio 2019 社区预览版,版本 16.4.0 预览版 1.0。 I just update to Windows 10 Pro Version 1903 OS build 18362.418.我刚刚更新到 Windows 10 Pro 版本 1903 OS build 18362.418。 With ASP.NET Core 3 web-app project (Blazor Server), When I press F5 , I catch error使用 ASP.NET Core 3 web-app 项目(Blazor 服务器),当我按F5时,我发现错误

I can go to https://localhost:44333/ manually, but it is inconvenient.我可以手动 go 到https://localhost:44333/ ,但这很不方便。 When I stop debug, I also turn off it manually at taskbar.当我停止调试时,我也在任务栏手动关闭它。

With another web-app project, the problem is not happen.对于另一个网络应用程序项目,问题不会发生。

When I choose or not choose option Enable native code debugging , not success.当我选择或不选择选项Enable native code debugging时,不成功。

How to fix it?如何解决?

Enable/disable SSL启用/禁用 SSL

This is the easy fix.这是简单的解决方法。 For me, toggling the "Enable SSL" setting in the project Debug tab inside Visual Studio (just change it to the opposite of what is currently set and run the project) has fixed the issue.对我来说,在 Visual Studio 的项目调试选项卡中切换“启用 SSL”设置(只需将其更改为与当前设置的相反并运行项目)已经解决了这个问题。

As I understand it, there are two reason this might work.据我了解,这可能有两个原因。 First it causes Visual Studio to update the Applicationhost Config (more about that later).首先,它会导致 Visual Studio 更新 Applicationhost 配置(稍后会详细介绍)。 Secondly, sometimes the SSL address is bound.其次,有时SSL地址是绑定的。 Therefore disabling SSL disables the problem.因此禁用 SSL 会禁用该问题。

Applicationhost Config应用程序主机配置

Open your $(solutionDir)\.vs\config\applicationhost.config file and ensure your site looks like this:打开您的$(solutionDir)\.vs\config\applicationhost.config文件并确保您的站点如下所示:

<site name="[YOUR PROJECT NAME]" id="3">
  <application path="/" applicationPool="Clr4IntegratedAppPool">
    <virtualDirectory path="/" physicalPath="//PATH/TO/YOUR PROJECT" />
  </application>
  <bindings>
    <binding protocol="http" bindingInformation="*:[YOUR_PORT]:localhost" />
    <binding protocol="https" bindingInformation="*:[YOUR_SSL_PORT]:localhost" />
  </bindings>
</site>

Make sure iplisten is configured to 0.0.0.0确保 iplisten 配置为 0.0.0.0

If the IP listen list is not configured, this issue may occur (caution, I have no idea why).如果没有配置 IP 监听列表,可能会出现这个问题(注意,我不知道为什么)。

Check netsh to ensure there is an entry for 0.0.0.0检查 netsh 以确保有 0.0.0.0 的条目

PS C:\Windows\system32> netsh http show iplisten

IP addresses present in the IP listen list:
-------------------------------------------

::     
0.0.0.0

PS C:\Windows\system32>

Add the correct netsh rule if it does not exists.如果不存在,请添加正确的 netsh 规则。 You'll need an admin cmd.exe or admin PowerShell for this.为此,您需要管理员 cmd.exe 或管理员 PowerShell。

PS C:\Windows\system32> netsh http add iplisten ipaddress=0.0.0.0

Ensure nothing is binding to the address you are using确保没有任何东西绑定到您正在使用的地址

This seems to be an issue with Blazor for me.对我来说,这似乎是 Blazor 的问题。 If an address is binded to the address Blazor is trying to use, this can cause issues.如果地址绑定到 Blazor 尝试使用的地址,这可能会导致问题。 Use netsh again to check what is in use.再次使用netsh检查正在使用的内容。

netsh http show urlacl

An entry that looks like this一个看起来像这样的条目

Reserved URL            : http://*:50902/
    User: \Everyone
    Listen: Yes
    Delegate: No
    SDDL: D:(A;;GX;;;WD)

Can be deleted with this command可以用这个命令删除

netsh http del urlacl url=http://*:50902/

I had the very same issue what OP described, I mean I got the error message, but checking the IIS Express icon, it was shown everything is OK, so manually going to the url was working.我遇到了与 OP 描述的完全相同的问题,我的意思是我收到了错误消息,但检查 IIS Express 图标,显示一切正常,因此手动转到 url 工作正常。

Tried literally everything what is described above including从字面上尝试了上面描述的所有内容,包括

  • Stop the site within IIS Express站内IIS快递
  • Stop IIS Express停止IIS快递
  • Exit VS restart VS退出VS重启VS
  • Check everything in the.vs folder检查 .vs 文件夹中的所有内容
  • Delete the.vs folder删除.vs文件夹
  • as a POC created a brand new ASP.NET Core project, that worked properly作为 POC 创建了一个全新的 ASP.NET 核心项目,它工作正常

Nothing helped.没有任何帮助。

I know it is ridiculous as "solution", but after spending a half hour with this I finally restarted my machine and everything is working since then... Worth a try我知道这作为“解决方案”很荒谬,但是在花了半个小时之后,我终于重新启动了我的机器,从那时起一切正常......值得一试

Thought I would throw in what worked for me even though I'm late to the party.以为即使我参加聚会迟到了,我也会投入对我有用的东西。 The solutions above didn't work for me.上面的解决方案对我不起作用。

  1. Went to the properties of the project -> Debug Tab转到项目的属性-> 调试选项卡
  2. Changed the port number in the AppURL to x + 1, ie for my instance http://localhost:44348 => http://localhost:44349将 AppURL 中的端口号更改为 x + 1,即对于我的实例 http://localhost:44348 => http://localhost:44349
  3. Closed the solution关闭解决方案
  4. Deleted the applicationhost config删除了应用程序主机配置
  5. Reopened solution.重新打开解决方案。
  6. Changed the port number back to the original将端口号改回原来的

Voila

I have had this problem occasionally in the past.我过去偶尔会遇到这个问题。 I can often resolve the problem by:我通常可以通过以下方式解决问题:

  1. Click on show hidden icon area of task bar.单击任务栏的显示隐藏图标区域。 You'll see an IIS Express icon.您将看到 IIS Express 图标。
  2. Select the icon and you should see your website listed. Select 图标,您应该会看到您的网站已列出。 Drill down in that menu click "Stop site".在该菜单中向下钻取,单击“停止站点”。

On other occasions I have had corporate security software interfere with Visual Studio/IIS Express operations.在其他情况下,我曾让企业安全软件干扰 Visual Studio/IIS Express 操作。 Usually you can get around the issue by running Visual Studio as Administrator.通常,您可以通过以管理员身份运行 Visual Studio 来解决此问题。 I've attempt explain to the security guys what an awful idea that is but usually they do not understand.我试图向安全人员解释这是一个多么糟糕的想法,但他们通常不明白。

Finally, if you are running a Asp.Net Core application you can just give up on IIS Express.最后,如果您正在运行 Asp.Net Core 应用程序,您可以放弃 IIS Express。 If you look next to the play button, there is a drop list that says "IIS Express".如果您查看播放按钮旁边,有一个下拉列表显示“IIS Express”。 If you open the list you'll see your application's name there.如果您打开列表,您将在那里看到您的应用程序的名称。 Select that one. Select 那一个。 You'll be running using kestrel instead of IIS Express.您将使用 kestrel 而不是 IIS Express 运行。

I had the same issue, I was able to solve it by changing the Port number.我有同样的问题,我可以通过更改端口号来解决它。

  1. Right click on the project and select properties右键单击项目和 select 属性
  2. Go to the Debug section Go 到调试部分
  3. Under Web Server Settings change App URL port [just increase by one] Web Server Settings下更改App URL端口【就加一】

Nothing worked for me (including deleting .vs , deleting obj and bin , cleaning the projects, restarting VS Studio, running netstat -ao | findstr <port number> to find out who is using my port and so on) .对我没有任何帮助(包括删除.vs 、删除objbin 、清理项目、重新启动 VS Studio、运行netstat -ao | findstr <port number>以找出谁在使用我的端口等等) Nothing.没有什么。

Nothing except this:除了这个:

  1. Open PowerShell as an administrator以管理员身份打开PowerShell
  2. Run Get-Process -Id (Get-NetTCPConnection -LocalPort MY-PORT-NUMBER).OwningProcess (change port number to your port number)运行Get-Process -Id (Get-NetTCPConnection -LocalPort MY-PORT-NUMBER).OwningProcess (将端口号更改为您的端口号)
  3. Finally, in my case, this showed that this process: service host: windows push notifications system service is using my port.最后,在我的情况下,这表明这个过程: service host: windows push notifications system service正在使用我的端口。 Note the ID of this process and..记下这个进程的ID和..
  4. Go to Task Manager (more details) > Processes > find the process by that ID and kill the child process (because this parent process itself can't be killed without the system becoming unusable ) Go 到任务管理器(更多详细信息)> 进程 > 通过该ID查找进程并杀死子进程(因为在系统不可用的情况下无法杀死该父进程本身)

That's it.而已。 It was windows push notifications system service in my case.就我而言,它是windows push notifications system service Once I found it and killed it - everything is working without having to restart the whole computer or changing the port number .一旦我找到它并杀死它 - 一切正常,无需重新启动整个计算机或更改端口号

I resolved this by closing Visual Studio (2019) and started it back up, running as Administrator.我通过关闭 Visual Studio (2019) 解决了这个问题并重新启动它,以管理员身份运行。

For me I had another application using the same port, I changed the port in project debug settings to something else.对我来说,我有另一个使用相同端口的应用程序,我将项目调试设置中的端口更改为其他内容。

Changing the application url (by right clicking on the solution -> properties -> debug -> app url) from http://localhost:59017 to http://localhost:5901 (last number 7 deleted) worked for me.将应用程序 url (通过右键单击解决方案 -> 属性 -> 调试 -> 应用程序 url)从 http://localhost:59017 更改为 Z80791B3AE7002CB88C2Z 已删除7为我:6876D9FAA8F。 在此处输入图像描述

Removing .vs folder will solve this issue.删除.vs文件夹将解决此问题。

  1. Go to application location Go 到应用位置
  2. Remove .vs folder(hidden folder)删除.vs文件夹(隐藏文件夹)
  3. Start project again!再次启动项目!

Another option, and the one I prefer because one should not have to waste time fighting with IISExpress, is to run your project launch profile and not the IISExpress one.另一种选择,也是我更喜欢的一种选择,因为不必浪费时间与 IISExpress 打架,它是运行您的项目启动配置文件而不是 IISExpress 配置文件。

Blazor is a .NET Core app so you can debug it with Kestrel. Blazor 是 .NET 核心应用程序,因此您可以使用 Kestrel 对其进行调试。

I had the same issue.我遇到过同样的问题。 I was connected to my organization VPN.我已连接到我的组织 VPN。 I simply disconnected the VPN, restarted IIS and tried again.我只是断开了 VPN,重新启动了 IIS 并再次尝试。 It works fine now,现在工作正常,

I had exactly the same problem with IIS Express that seemingly appeared out of nowhere.我在 IIS Express 上遇到了完全相同的问题,似乎突然出现。 My solution was to simply open IIS Manager and restart IIS (in the right-side panel under Actions -> Manage Server).我的解决方案是简单地打开 IIS 管理器并重新启动 IIS(在右侧面板中的操作 -> 管理服务器下)。 As a result, project start-up resumed working right away.结果,项目启动立即恢复工作。

I was facing same issue, i tried all the way, i did not get proper solution.我面临同样的问题,我一直尝试,我没有得到正确的解决方案。 Finally i was resolved using below steps.最后我使用以下步骤解决了。 In VS goto Tools=>Options=>Projects and solutions=>Web projects=> click checkbox -Use the 64 bit version of IIS express for website and projects.在 VS 中转到工具 => 选项 => 项目和解决方案 => Web 项目 => 单击复选框 - 使用 64 位版本的 IIS express 用于网站和项目。

With this i came out of my issue.有了这个,我就摆脱了我的问题。

I seem to have this annoying issue when there are more than one solution with the same name on the same workstation.当同一个工作站上有多个同名的解决方案时,我似乎遇到了这个烦人的问题。 The host file ends up having names app, app(1), app(2), app(N) and so on.主机文件最终具有名称 app、app(1)、app(2)、app(N) 等。 The solution here is to manually adjust the host file to your likings in \app(N).vs\app\config\applicationhost.config to align with whatever port you set in Properties>Web>Project URL.此处的解决方案是根据您的喜好在 \app(N).vs\app\config\applicationhost.config 中手动调整主机文件,以与您在 Properties>Web>Project URL 中设置的任何端口对齐。 You may also need to unload project and set the same port number in project config.您可能还需要卸载项目并在项目配置中设置相同的端口号。

Another thing to try if nothing works (or if you just want to get it working quick):如果没有任何效果(或者如果您只想让它快速工作),请尝试另一件事:

Uninstall IIS Express, and then re-install it - can be done from Visual Studio Installer components (Add/Remove).卸载 IIS Express,然后重新安装它 - 可以从 Visual Studio 安装程序组件(添加/删除)中完成。

All the above solutions did not work for me, however what worked was a simple fix after going through multiple solution;以上所有解决方案都对我不起作用,但是在经过多个解决方案后,一个简单的解决方案是有效的;

Please follow the steps below;请按照以下步骤操作;

  1. Go to your project/main solution folder in visual studio Go 到 Visual Studio 中的项目/主解决方案文件夹
  2. Right click on it and choose properties右键单击它并选择属性
  3. Go to the debug tab Go 到调试选项卡
  4. Scroll down to the Web Server Settings and turn off SSL向下滚动到 Web 服务器设置并关闭 SSL

在此处输入图像描述

  1. Run your solution again, and you should be able to continue without errors再次运行您的解决方案,您应该能够继续没有错误

This always works for me:这总是对我有用:

  1. Delete the "launchSettings.json" inside the "Properties" folder in the Project删除项目中“Properties”文件夹中的“launchSettings.json”
  2. Open the project in Visual Studio在 Visual Studio 中打开项目
  3. Rebuild the project重建项目
  4. Debug (F5) or Run (Ctrl + F5).调试 (F5) 或运行 (Ctrl + F5)。

Have a Happy Coding:)有一个快乐的编码:)

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

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