Thursday, December 19, 2013

How to fix cryptography exception while request shared among multiple servers by load balancer on session time out

Solution: - Please follows the following steps:-

Step1:- Change the namespace throughout the application to “using System.IdentityModel;”


Step2:- Add the following code on Application_Start () section in global.asax

var sam = new SessionAuthenticationModule(); sam.SessionSecurityTokenReceived += sam_SessionSecurityTokenReceived; FederatedAuthentication.FederationConfigurationCreated += FederatedAuthentication_FederationConfigurationCreated;

And generate the following events

void FederatedAuthentication_FederationConfigurationCreated(object sender, System.IdentityModel.Services.Configuration.FederationConfigurationCreatedEventArgs e) { var sessionTransforms = new List(new CookieTransform[] { new DeflateCookieTransform(), new RsaEncryptionCookieTransform( e.FederationConfiguration.ServiceCertificate), new RsaSignatureCookieTransform( e.FederationConfiguration.ServiceCertificate) }); var sessionHandler = new SessionSecurityTokenHandler(sessionTransforms.AsReadOnly()); e.FederationConfiguration.IdentityConfiguration.SecurityTokenHandlers.AddOrReplace(sessionHandler); }

void sam_SessionSecurityTokenReceived(object sender, SessionSecurityTokenReceivedEventArgs e) { var _sam = sender as SessionAuthenticationModule; var sessionToken = e.SessionToken; DateTime now = DateTime.UtcNow; if (sessionToken.ValidTo > DateTime.UtcNow.AddMinutes(30)) { var slidingExpiration = sessionToken.ValidTo - now; e.SessionToken = _sam.CreateSessionSecurityToken( sessionToken.ClaimsPrincipal, sessionToken.Context, now, now + slidingExpiration, false ); e.ReissueCookie = true; } else { var sessionAuthenticationModule = (SessionAuthenticationModule)sender; sessionAuthenticationModule.DeleteSessionTokenCookie(); sessionAuthenticationModule.SignOut(); e.Cancel = true; } }


STEP3:- Add following section under in the web.config file. For localhost use this:

On the server, please replace localhost with “certificate name”


STEP4:- Make sure to use the same certificate in all the four servers. Following should be same in all the WFEs:

 Cert Name
 Thumbprint

Wednesday, September 25, 2013

How to configure SMTP with IIS 7 and windows server 2008

Make sure that SMTP windows feature is installed on the server. You can verify this by using the following steps :-

Step1 :- Go to control panel
Step2 :- Click on turn windows features on or off
Step3 :- Click on features and see if SMTP is installed. if not then click on Add Features from right top corner.
Step4:- Select SMTP and install it.




Next thing is to check that Simple Mail Transfer Protocol Service is enabled and running on the server. You can check this using following step:
Go to run window (windows icon+R) and type services.msc


Last step is to go to IIS 6.0 Manager from administrator tools and configure SMTP.

In case of any question, just let me know.



Rendering PDF using HTML DIV

Download and install notepad++ for better and advanced features of html and html5. If you have simple notepad.exe then that is enough. I am referring notepad++.


<!DOCTYPE html>
<html>
<head>
<title></title>
<body>
<object data="OneTerms.pdf" type="application/pdf"></object>

</body>
</html>

You can use the height and width as per your design for defined object.

Result :-

IIS 7.5 error: Handler “PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in its module list

This is the common error seen with IIS 7 with windows server 2008 R2. Here is the fix :-


Step1 :- Open the command window as an administrator.

Step2 :- Run the following command

%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i


Try again to open the web page, you should be good.