% @ LANGUAGE = VBScript %>
<% Option Explicit %>
<% Response.Buffer= true %>
Create New Certificate Mapping
<%
Dim objW3svr, objCertMapper, vntCertificate, vntAccnt, vntPassword, strMapName, bEnabled
vntAccnt = Request.form("AccountName")
vntPassword = Request.form("Password")
strMapName = Request.form("MapName")
If Request.form("Enablemap")="true" then
bEnabled = true
Else
bEnabled = false
End If
If vntAccnt <>"" Then
Err.Clear
On Error Resume Next
vntCertificate = Request.ClientCertificate("CERTIFICATE")
If vntCertificate = "" Then
Response.Write "No cert is presented
"
End If
Set objW3svr = GetObject("IIS://localhost/W3svc/1")
If Err.Number<>0 Then
Response.Write "Function GetObject failed!
"
Response.End
End If
Set objCertMapper = objW3svr.GetObject("IISCertMapper", "MyCertMapper")
'if failed, try to create new IISCertMapper Object
If Err.number<>0 then
Err.clear
Set objCertMapper = objW3svr.Create("IISCertMapper", "MyCertMapper")
If Err.Number <>0 Then
Response.Write "Could not create IISCertMapper object!
"
Response.End
Else
'objCertMapper.SetInfo
objW3svr.SetInfo
End if
End If
objCertMapper.CreateMapping vntCertificate, vntAccnt, vntPassword, strMapName, bEnabled
If Err.number <>0 Then
Response.Write "Mapping Failed
See following instruction
"
Else
Response.Write "You have succeded to create a new mapping
"
End If
Set objCertMapper=Nothing
Set objW3svr = Nothing
End If
%>
For this sample to work properly, You need to do following:
1.Require SSL to access this asp page.
2.Require client certificate.
3.uncheck anonymous authentication.
4.install client certificate into your browser.