如何更改Windows 11上IIS中的SSL配置?

发布于 2025-01-26 04:16:10 字数 1160 浏览 5 评论 0原文

我使用以下代码在IIS中创建了一个网站:

我在服务器证书下导出了IIS证书:

name = "TestSite"
port = 5858
location = location of my install files.


 using (ServerManager iisManager = new ServerManager())
 {        
    Site website = iisManager.Sites.Add(name, location, port); 
    X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
    store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadWrite);
    X509Certificate2 certificate = new X509Certificate2(@"c:\certs\testwcf.pfx", 
      "pwd>");
    store.Add(certificate);
    var binding = website.Bindings.Add("*:443:", certificate.GetCertHash(), store.Name);
    binding.Protocol = "https";
    store.Close();
    website.Applications[0].ApplicationPoolName = appPoolName;
    website.ServerAutoStart = true;
    iisManager.CommitChanges();
 }

现在发生的是,如果我从Visual Studio运行任何其他开发解决方案 我发现错误:

  "An error occurred while using SSL configuration for endpoint 0.0.0.0:87879.  The 
   error status code is contained within the returned data."

开发网站出现后,它将其重定向到Localhost,我似乎无法访问https:// localhost:87879,它使用IIS Express。

我不知道如何 我在哪里可以从哪里看这个想法?

I created a website in IIS using the following code:

I exported a certificate from IIS under Server Certificates to use:

name = "TestSite"
port = 5858
location = location of my install files.


 using (ServerManager iisManager = new ServerManager())
 {        
    Site website = iisManager.Sites.Add(name, location, port); 
    X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
    store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadWrite);
    X509Certificate2 certificate = new X509Certificate2(@"c:\certs\testwcf.pfx", 
      "pwd>");
    store.Add(certificate);
    var binding = website.Bindings.Add("*:443:", certificate.GetCertHash(), store.Name);
    binding.Protocol = "https";
    store.Close();
    website.Applications[0].ApplicationPoolName = appPoolName;
    website.ServerAutoStart = true;
    iisManager.CommitChanges();
 }

Now whats happening is that if i run any other development solutions from Visual Studio
I get the error:

  "An error occurred while using SSL configuration for endpoint 0.0.0.0:87879.  The 
   error status code is contained within the returned data."

When the development site comes up it redirects to localhost and I cant seem to reach https://localhost:87879, which uses IIS Express.

I am not sure how but I think i have broken something in the bindings in IIS which is affecting localhost
Where can i start to look at this any ideas ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鯉魚旗 2025-02-02 04:16:10

设法使它继续前进。
对于任何有此问题的人,请尝试以下内容:

从高架命令提示下运行:

cd c:\ program文件(x86)\ iis express iisexpressadmincmd.exe
setupsslurl -url:urltoyoursite -usefsigned

用您的URL代替urltoyoursite。

例如

CD C:\ Program Files(x86)\ iis Express
iisexpressadmincmd.exe setupsslurl -url:https:// localhost:44387/-isselfSigned

Managed to get it going.
For any one having this issue try the following:

From an elevated command prompt run:

cd C:\Program Files (x86)\IIS Express IisExpressAdminCmd.exe
setupsslUrl -url:urlToYourSite -UseSelfSigned

Replacing urlToYourSite with your url.

e.g.

cd C:\Program Files (x86)\IIS Express
IisExpressAdminCmd.exe setupsslUrl -url:https://localhost:44387/ -UseSelfSigned

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文