在我的 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" />
但是,我仍然会收到关于站点加载证书的提示。我首先得到以下屏幕:
单击“继续访问此网站”后,我会在加载 Default.aspx 时收到选择证书的提示。但是,我只想在加载 SmartCard/WebForm1.aspx 时收到选择证书的提示!
非常感谢任何帮助!
这是我在 IIS-7 中的站点设置:
SSL 设置:
*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/access 和 https://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/