Tuesday, December 25, 2012

FBA Cookie getting expired only in Safari and Chrome.

Hi Reader,

This blog is for all those guys who have tried their level best to solve this unique issue and still couldnt get the root cause why the Form Based Authentication Cookie getting expired daily ( almost after some hours ) ONLY on Safari and Chrome browser.

I have spend lot many days finding the root cause of this issue and yes also solve it for clients.
Applicaiton that use hosted Safari inside of UIWebView ( which is also Chrome) or Apps that host a website in PhoneGap usually face this issue. If its FBA then Google Chrome for iOS might switch FormsAuth to Cookieless mode.

This has been fixed in .NET 4.5 and you wont see this issue if you have .NET 4.5 installed, even uf you're running .NET 4 application. Since now you are facing this trouble then here are following steps to follow and immediately get rid of this issue.

Thanks to blogger: Scott

STEP 1:  Modify your web.config file.

<authentication mode="Forms" >
  <forms loginUrl="~/Account/SignIn" timeout="2880" cookieless="UseCookies" />
</authentication>


STEP 2:  Once you explore your Sharepoint hosted site in IIS you will notice the app_browser folder.
Create a "generic.browser" named file in that folder and paste the exact code in it.


<browsers>
  <browser refID="GenericDownlevel"> 
    <capabilities> 
      <capability name="cookies" value="true" /> 
    </capabilities>
  </browser>
</browsers>



STEP 3: Generate a New MachineKey.

“Machine key a unique key that differentiates one computer from others. And this key is used to create unique identifier when cookie is created in the client machine from a server side code. This key is generally present in the machine.config file when you install .NET framework that is generally not visible to the user as it remains in the .NET Framework installation directory. When you specify the same key in your web.config, the value of machine key specified in the machine.config is overridden by the one you have specified in the web.config file. “
Once the key is generated, they are converted into a string of hexadecimal characters.
Created a 256-bit decryption key and a 512-bit validation key, with Rijndael as the data validation algorithm.
You need to include this newly created machine key in your web.config file.




Hope my above solution will surely save lot of efforts and time.






No comments:

Post a Comment