c# - 如何将特定页面限制为证书身份验证?

标签 c# asp.net ssl iis-7 x509certificate

在我的 ASP.NET 网络应用程序中,我创建了 Default.aspx(设置为我的起始页)和一个名为 SmartCard 的新文件夹,其中包含 WebForm1.aspx。如何配置 Web.Config 以在访问 SmartCard/WebForm1.aspx 时提示用户输入证书,而不是在加载 Default.aspx 时提示用户输入证书?

this 的已接受答案中问题:

if your app is hosted in IIS then simply add (in web.config) a section that says client certificate is required for those pages. THe browser will then ask the user for a cert.

根据上面的回答,我在 StackOverflow 上看了更多,发现 this .根据他们接受的答案,我将以下部分放在 Web.Config 中:

<location path="SmartCard">
  <system.webServer>
    <security>
      <access sslFlags="SslRequireCert" />
    </security>
 </system.webServer>

然后我修改了 C:\Windows\System32\inetsrv\config(或适合您安装的目录)中的 applicationHost.config 并更改以下行:

<section name="access" overrideModeDefault="Deny" />

到:

<section name="access" overrideModeDefault="Allow" />

但是,我仍然会收到关于站点加载证书的提示。我首先得到以下屏幕:

enter image description here

单击“继续访问此网站”后,我会在加载 Default.aspx 时收到选择证书的提示。但是,我只想在加载 SmartCard/WebForm1.aspx 时收到选择证书的提示!

非常感谢任何帮助!


这是我在 IIS-7 中的站点设置:

SSL 设置:

enter image description here

网站绑定(bind): enter image description here enter image description here

*MyDevCert 是自签名的


更新:

我在 SmartCard 目录中创建了一个新的 Web.Config 文件,内容如下:

 <?xml version="1.0"?>
 <configuration>

    <security>
       <access sslFlags="SslRequireCert" />
    </security>
    <system.web></system.web>

 </configuration>

然后我从基础 Web.Config 中删除了“位置”标签。

基础 Web.Config:

<?xml version="1.0" encoding="UTF-8"?>

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <identity impersonate="false" />
  </system.web>
</configuration>

但是,我仍然看到“此网站的安全证书有问题”屏幕,并且在我单击“继续访问此网站”后提示我输入证书

最佳答案

据我所知,sslFlags 只能有一个值。

参见 http://www.iis.net/configreference/system.webserver/security/accesshttps://msdn.microsoft.com/en-us/library/ms689458(v=VS.90).aspx

The sslFlags attribute can be one of the following possible values. The default is None.

关于c# - 如何将特定页面限制为证书身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31728866/

相关文章:

c# - 正则表达式在 C# 中匹配,但在 java 中不匹配

python-3.x - SSL Socket Python 非阻塞

javascript - 如何在 asp.net mvc 中刷新页面后保留注入(inject)的局部 View

asp.net/VB.net : FindControl, 而不是通过 ControlType 通过 ID

ruby - 有人在 Ruby 1.9.3 下使用 FTPS/FTP::TLS 吗?

C# 如何解决 HtppWebResponse return Could not establish trust relationship for the [SSL/TLS] secure channel?

c# - 如何使用 C# 下载并解压缩 gzip 文件?

c# - 在任务栏中显示隐藏窗口的图标

c# - 在 c# 中,Array.ToArray() 执行深度复制吗?

asp.net GridView IF 空显示消息