本地IIS上的数字签名与IIS Express的区别
创始人
2024-11-29 18:00:21
0

本地IIS上的数字签名与IIS Express的区别主要在于签名证书的安装和配置。下面是一些解决方法的代码示例:

  1. 本地IIS上的数字签名
using System.Security.Cryptography.X509Certificates;

// 安装数字证书
X509Certificate2 certificate = new X509Certificate2("path_to_certificate.pfx", "certificate_password");
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadWrite);
store.Add(certificate);
store.Close();

// 配置IIS绑定
using (ServerManager serverManager = new ServerManager())
{
    Configuration config = serverManager.GetApplicationHostConfiguration();
    ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites");
    ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();
    ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", "Default Web Site");
    if (siteElement == null) throw new Exception("Site not found!");
    
    ConfigurationElementCollection bindingsCollection = siteElement.GetCollection("bindings");
    ConfigurationElement bindingElement = bindingsCollection.CreateElement("binding");
    bindingElement["protocol"] = "https";
    bindingElement["bindingInformation"] = "*:443:";
    bindingElement["certificateHash"] = certificate.GetCertHash();
    bindingElement["certificateStoreName"] = "My";
    bindingsCollection.Add(bindingElement);
    
    serverManager.CommitChanges();
}
  1. IIS Express上的数字签名
using System;
using System.Diagnostics;
using System.IO;

// 将数字证书复制到IIS Express的证书存储目录
string iisExpressCertPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".aspnet", "https", "mycert.pfx");
File.Copy("path_to_certificate.pfx", iisExpressCertPath, true);

// 配置IIS Express绑定
ProcessStartInfo startInfo = new ProcessStartInfo
{
    FileName = "iisexpress.exe",
    Arguments = $"/config:\"{Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), \"IIS Express\", \"config\", \"applicationhost.config\")}\" /site:Default Web Site",
    RedirectStandardOutput = true,
    UseShellExecute = false,
    CreateNoWindow = true
};

using (Process process = new Process())
{
    process.StartInfo = startInfo;
    process.OutputDataReceived += (sender, e) =>
    {
        if (e.Data != null && e.Data.Contains("

以上代码示例分别演示了如何在本地IIS和IIS Express上安装数字证书并配置绑定。请根据实际情况修改代码中的路径和配置信息。

相关内容

热门资讯

3分钟辅助!aapoker万能... 3分钟辅助!aapoker万能辅助器,wepoker买脚本靠谱吗,大纲教程(的确有挂)3分钟辅助!a...
第9分钟辅助!德州局透视脚本,... 第9分钟辅助!德州局透视脚本,wepoker透视是真的吗,手段教程(有挂秘诀)wepoker透视是真...
5分钟辅助!hhpoker有没... 5分钟辅助!hhpoker有没有辅助,德州局hhpoker,举措教程(有人有挂)1、进入到hhpok...
八分钟辅助!竞技联盟透视插件,... 八分钟辅助!竞技联盟透视插件,wepoker软件辅助程序,绝活教程(存在有挂)1、点击下载安装,we...
第八分钟辅助!pokernow... 第八分钟辅助!pokernow辅助工具,购买的wpk辅助在哪里下载,练习教程(揭秘有挂)1)购买的w...
三分钟辅助!werplan免费... 您好,wepoker怎么设置透视这款游戏可以开挂的,确实是有挂的,需要了解加去威信【48527505...
第二分钟辅助!wepoker怎... 第二分钟辅助!wepoker怎么开辅助,wpk作弊是真的吗,指引教程(有挂工具)1、这是跨平台的we...
十分钟辅助!wepoker辅助... 十分钟辅助!wepoker辅助器软件下载,wepoker透视版下载,秘籍教程(发现有挂)1、打开软件...
第九分钟辅助!wepoker游... 第九分钟辅助!wepoker游戏安装教程,aapoker脚本,手筋教程(真的有挂)1、进入游戏-大厅...
第六分钟辅助!wpk透视是真的... 第六分钟辅助!wpk透视是真的假的,xpoker怎么作弊,阶段教程(有挂分析)1、进入游戏-大厅左侧...