Вам не нужно использовать iisClientCertificateMappingAuthentication. Сертификат клиента доступен в HttpContext.
var clientCert = HttpContext.Request.ClientCertificate;
Либо вы включаете RequireClientCertificate на весь сайт, либо используете отдельную страницу login-with-clientcertificate .
Ниже приведен один из способов сделать это в ASP.NET MVC. Надеемся, вы сможете использовать его части, чтобы соответствовать вашей конкретной ситуации.
[/g1]
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
[AllowAnonymous()]
public ActionResult CertificateSignIn()
{
//Get certificate
var clientCert = HttpContext.Request.ClientCertificate;
//Validate certificate
if (!clientCert.IsPresent || !clientCert.IsValid)
{
ViewBag.LoginFailedMessage = "The client certificate was not present or did not pass validation";
return View("Index");
}
//Call your "custom" ClientCertificate --> User mapping method.
string userId;
bool myCertificateMappingParsingResult = Helper.MyCertificateMapping(clientCert, out userId);
if (!myCertificateMappingParsingResult)
{
ViewBag.LoginFailedMessage = "Your client certificate did not map correctly";
}
else
{
//Use custom Membersip provider. Password is not needed!
if (Membership.ValidateUser(userId, null))
{
//Create authentication ticket
FormsAuthentication.SetAuthCookie(userId, false);
Response.Redirect("~/");
}
else
{
ViewBag.LoginFailedMessage = "Login failed!";
}
}
return View("Index");
}