You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visual Studio + WSL环境证书导出失败,寻求修复方案

解决WSL中ASP.NET证书导出失败问题

1. 手动生成并导入ASP.NET开发证书到WSL

  • 以管理员身份打开Windows命令提示符,清理现有开发证书:
    dotnet dev-certs https --clean
    
  • 重新生成并信任证书:
    dotnet dev-certs https -t
    
  • 将证书导出到桌面(密码留空):
    dotnet dev-certs https --export-path "%USERPROFILE%\Desktop\aspnet-dev-cert.pfx" --password ""
    
  • 切换到WSL终端,复制证书到Linux用户目录(替换成你的Windows用户名):
    cp /mnt/c/Users/你的Windows用户名/Desktop/aspnet-dev-cert.pfx ~/
    
  • 在WSL中安装证书到系统信任存储:
    sudo mkdir -p /usr/local/share/ca-certificates/aspnet
    sudo cp ~/aspnet-dev-cert.pfx /usr/local/share/ca-certificates/aspnet/
    sudo update-ca-certificates
    
  • 运行项目时指定证书(或修改项目launchSettings.json配置对应参数):
    dotnet run --urls=https://0.0.0.0:5001 --certificate-path ~/aspnet-dev-cert.pfx --certificate-password ""
    

2. 检查WSL与Windows的互操作配置

  • 执行wsl --shutdown完全关闭WSL
  • 在Windows的C:\Users\你的用户名\.wslconfig(无则新建)中添加:
    [interop]
    enabled = true
    appendWindowsPath = true
    
  • 重启WSL后,验证是否能访问Windows证书目录:
    ls /mnt/c/Users/你的Windows用户名/AppData/Roaming/Microsoft/SystemCertificates/My/Certificates/
    

3. 重置Visual Studio的WSL关联

  • 打开Visual Studio,进入工具 > 选项 > 项目和解决方案 > Web项目,确认勾选使用WSL进行ASP.NET Core开发
  • 删除项目根目录下的bin、obj和.vs隐藏目录
  • 重新生成解决方案并尝试运行

内容的提问来源于stack exchange,提问作者10101

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 00:28:15