Visual Studio ASP.NET Core调试IIS Express-无法访问网站

如何解决Visual Studio ASP.NET Core调试IIS Express-无法访问网站

我一直在Windows 10 PC上的VS 2019中开发ASP.NET Core 2.1 Web应用程序。一切运行正常,并且在Chrome / IIS Express中进行调试没有问题。

我将项目复制到了刚开始使用的新Win 10计算机上。

当我尝试在Chrome中使用IIS Express调试项目时,出现错误页面,提示:无法访问此站点。

我遵循了Overflow文章中的所有建议的修复程序,但是似乎没有任何效果。这让我发疯,浪费了很多时间。我已经尝试了所有这些步骤,但没有任何乐趣:

  • 禁用防病毒防火墙/保护
  • 检查项目属性(与以前的PC相同)
  • 检查launchSettings.json文件(与以前的PC相同)
  • 删除vs / config文件夹中的applicationhost.config(帖子说此文件将在重建时重新创建,但是重建文件仍然不存在!)
  • 删除obj文件夹并重建
  • 删除vs文件夹并重建
  • 检查Windows功能(与运行正常的旧PC相同)
  • 更改VS选项/调试:取消选中“启用编辑并继续”复选框
  • 以管理员身份运行cmd:cd“ C:\ Program Files(x86)\ IIS Express” IisExpressAdminCmd.exe setupsslUrl -url:https:// localhost:44301 / -UseSelfSigned

launchSettings.json 文件

launchSettings.json
{
  "iisSettings": {
    "windowsAuthentication": true,"anonymousAuthentication": true,"iisExpress": {
      "applicationUrl": "https://localhost:44301/","sslPort": 44376
    }
  },"profiles": {
    "IIS Express": {
      "commandName": "IISExpress","launchBrowser": true,"environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },"CanvasWeb": {
      "commandName": "Project","environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },"applicationUrl": "http://localhost:61900/"
    }
  }
}

Project Properties

更新

我尝试了以下操作,但仍未解决问题:

  • 修复了IIS Express
  • 在证书存储中没有检查重复的证书
  • 已删除证书,以使IIS生成新证书
  • 创建了一个新的“测试”项目-发生相同的问题

解决方法

问题可能是 IIS Express 的 HTTPS 错误。 要检查它: 创建一个没有 Https 的新 ASP.NET Core Web 应用程序。 在 Web 应用程序模板中取消选中 /deselect configure for https Uncheck configure for https

如果新的 Web 应用程序运行,则是 IIS Express HTTPS 问题。 使用管理员权限运行流畅的 power shell 代码将解决 IIS Express 问题。

# code start
Start-Transcript -Path "$($MyInvocation.MyCommand.Path).log"
try {
    Write-Host "Creating cert resources"
    $ekuOidCollection = [System.Security.Cryptography.OidCollection]::new();
    $ekuOidCollection.Add([System.Security.Cryptography.Oid]::new("1.3.6.1.5.5.7.3.1","Server Authentication")) | Out-Null
    $sanBuilder = [System.Security.Cryptography.X509Certificates.SubjectAlternativeNameBuilder]::new();
    $sanBuilder.AddDnsName("localhost") | Out-Null
    
    Write-Host "Creating cert extensions"
    $certificateExtensions = @(
        # Subject Alternative Name
        $sanBuilder.Build($true),# ASP.NET Core OID
        [System.Security.Cryptography.X509Certificates.X509Extension]::new(
            "1.3.6.1.4.1.311.84.1.1",[System.Text.Encoding]::ASCII.GetBytes("IIS Express Development Certificate"),$false),# KeyUsage
            [System.Security.Cryptography.X509Certificates.X509KeyUsageExtension]::new(
                [System.Security.Cryptography.X509Certificates.X509KeyUsageFlags]::KeyEncipherment,$true),# Enhanced key usage
        [System.Security.Cryptography.X509Certificates.X509EnhancedKeyUsageExtension]::new(
            $ekuOidCollection,# Basic constraints
            [System.Security.Cryptography.X509Certificates.X509BasicConstraintsExtension]::new($false,$false,$true)
        )
    Write-Host "Creating cert parameters"
    $parameters = @{
        Subject = "localhost";
        KeyAlgorithm = "RSA";
        KeyLength = 2048;
        CertStoreLocation = "Cert:\LocalMachine\My";
        KeyExportPolicy = "Exportable";
        NotBefore = Get-Date;
        NotAfter = (Get-Date).AddYears(1);
        HashAlgorithm = "SHA256";
        Extension = $certificateExtensions;
        SuppressOid = @("2.5.29.14");
        FriendlyName = "IIS Express Development Certificate"
    }
    Write-Host "Creating cert"
    $cert = New-SelfSignedCertificate @parameters

    $rootStore = New-Object System.Security.Cryptography.X509Certificates.X509Store -ArgumentList Root,LocalMachine
    $rootStore.Open("MaxAllowed")
    $rootStore.Add($cert)
    $rootStore.Close()
    
    Write-Host "Creating port bindings"
    # Add an Http.Sys binding for port 44300-44399
    $command = 'netsh'
    for ($i=44300; $i -le 44399; $i++) {
        $optionsDelete = @('http','delete','sslcert',"ipport=0.0.0.0:$i")
        $optionsAdd = @('http','add',"ipport=0.0.0.0:$i","certhash=$($cert.Thumbprint)",'appid={214124cd-d05b-4309-9af9-9caa44b2b74a}')
        Write-Host "Running $command $optionsDelete"
        & $command $optionsDelete
        Write-Host "Running $command $optionsAdd"
        & $command $optionsAdd
    } 
}
catch {
    Write-Error $_.Exception.Message
}
finally {
    Stop-Transcript
}
# code End

参考: HTTPS Error using IIS Express #26437

,

我确实遇到了这个问题,并在互联网上进行了一些研究,但是我找不到解决方案。然后,我决定关闭我的防病毒软件(卡巴斯基安全软件 21.2)并检查它是否能解决问题,之后一切都开始工作了!不幸的是,我找不到负责网络活动的防病毒设置,因此,即使是现在,如果我在 .NET 中测试后端 API,我也必须关闭防病毒一段时间 ((

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)> insert overwrite table dwd_trade_cart_add_inc > select data.id, > data.user_id, > data.course_id, > date_format(
错误1 hive (edu)> insert into huanhuan values(1,'haoge'); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive> show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 <configuration> <property> <name>yarn.nodemanager.res