本地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上安装数字证书并配置绑定。请根据实际情况修改代码中的路径和配置信息。

相关内容

热门资讯

线上(wepoke真的)原来是... 线上(wepoke真的)原来是真的有挂!其实真的有挂(2022已更新)(哔哩哔哩);亲,其实确实真的...
两教程(Wepoke程序)软件... 两教程(Wepoke程序)软件透明挂辅助工具(软件透明挂)透视辅助(2024已更新)(哔哩哔哩);致...
软件(wepoke透明)原来是... 软件(wepoke透明)原来是真的有挂!其实真的有挂(2020已更新)(哔哩哔哩)是一款可以让一直输...
一模拟器(德扑工具)外挂辅助工... 一模拟器(德扑工具)外挂辅助工具(透视)透视辅助(2025已更新)(哔哩哔哩);亲真的是有正版授权,...
系统(aapoker讲解)竟然... 系统(aapoker讲解)竟然真的有挂!其实真的有挂(2021已更新)(哔哩哔哩);aapoker讲...
6系统(aapoker下载)外... 6系统(aapoker下载)外挂辅助工具(辅助挂)透视辅助(2023已更新)(哔哩哔哩)aapoke...
智能(德扑之星刷数据)果真真的... 智能(德扑之星刷数据)果真真的有挂!原来真的有挂(2025已更新)(哔哩哔哩);《WPK辅助透视》‌...
1机器人(德州nzt软件)软件... 1机器人(德州nzt软件)软件透明挂辅助软件(透视)透视辅助(2022已更新)(哔哩哔哩);人气非常...
ai代打(德扑之星决策)确实是... ai代打(德扑之星决策)确实是真的有挂!原来真的有挂(2020已更新)(哔哩哔哩);科技详细教程小薇...
第8透明(wepoke数据)外... 第8透明(wepoke数据)外挂透明挂辅助神器(辅助挂)透视辅助(2023已更新)(哔哩哔哩);原来...