Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
Hi ,
When i create self-signed certificate from IIS and Import on cmm Personal and trusted level directory .
after when i run my application then i get a error .
System.Security.Cryptography.CryptographicException: Keyset does not exist.
at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)
   at System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)
   at System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()
   at System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()
   at System.IdentityModel.Tokens.X509AsymmetricSecurityKey.get_PrivateKey()

C#
<code>My Code is  This :
protected void SecureLoginButtonClick(object sender, EventArgs e)
{
string action = Request.QueryString[WSFederationConstants.Parameters.Action];

try
{
if (action == WSFederationConstants.Actions.SignIn)
{
// Process signin request.
SignInRequestMessage requestMessage = (SignInRequestMessage)WSFederationMessage.CreateFromUri(Request.Url);

if (WebHelper.IsAuthenticatedUser)
{
SecurityTokenService sts = new CustomSecurityTokenService(CustomSecurityTokenServiceConfiguration.Current);
SignInResponseMessage responseMessage = FederatedPassiveSecurityTokenServiceOperations.ProcessSignInRequest(requestMessage, User, sts);
FederatedPassiveSecurityTokenServiceOperations.ProcessSignInResponse(responseMessage, Response);
}
else
{
throw new UnauthorizedAccessException();
}
}
else
{
Response.Redirect("~/" + Constants.LoginPageName + SessionInfo.RedirectUrl);
}
}
catch (UnauthorizedAccessException exception)
{
Errorlog.AddException(exception.ToString());
Response.Redirect("~/" + Constants.LoginPageName + SessionInfo.RedirectUrl);
}
catch (ThreadAbortException ex)
{
}
catch (Exception exception)
{
Errorlog.AddException(exception.ToString());
throw;
}
}</code>
Posted
Updated 3-Nov-15 21:31pm
v4
Comments
Sergey Alexandrovich Kryukov 3-Nov-15 8:51am    
Excuse me, what's the use of exception stack without seeing the code throwing the exception?
—SA
Sergey Alexandrovich Kryukov 4-Nov-15 2:12am    
Could you move it into the body of the question, properly formatted? In comments, code is poorly readable.
—SA
Amresh Bahadur Singh 4-Nov-15 2:13am    
k
Sergey Alexandrovich Kryukov 4-Nov-15 2:37am    
How can I understand it? Why did you ignored my advice that badly and still gave me a comment?
Use "Improve question".
—SA
Amresh Bahadur Singh 4-Nov-15 3:40am    
Done Improve question , Please check ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900