Reputation: 3
When my ASP.NET site is browsed from a mobile device FormsAuthentication.CookiesSupported property sometimes returns false without any obvious reason. For example, I open my ASP.NET login page in mobile Safari and FormsAuthentication.CookiesSupported is true. After some period of inactivity I refresh this page and now FormsAuthentication.CookiesSupported is false. At this moment I open the same page in mobile Chrome or Dolphin and CookiesSupported is false in all of them as well. I then restart IIS and in some cases this leads to CookiesSupported being true again, sometimes it's still false, in all browsers. Again, after some time it may become true. Cookies support is always on in all browser configurations.
In cases when CookiesSupported is false and I call FormsAuthentication.SetAuthCookie function, ASP.NET uses URI for authentication ticket. I can live with that, but the changed URI causes another problem. The problem is that WebResource.axd stops working. asp:LinkButton, when rendered, calls WebForm_DoPostBackWithOptions which is not defined in cases when auth cookie is added to URI.
So basically, I have two questions:
Why does FormsAuthentication.CookiesSupported intermittently return false for mobile browsers (Safari, Chrome, Dolphin) and how this can be fixed?
Why does WebResource.axd stop working when authentication cookie is inserted into URI?
Upvotes: 0
Views: 557
Reputation: 3
I can finally post the complete solution here for those who may encounter the same problem on mobile browsers.
So, according to abhitalks's response I tried adding generic.browser file to my project and this solved the first problem with cookies. But the problem with WebResource.axd and missing WebForm_DoPostBackWithOptions javascript code was still there. This problem was solved by telling the framework that we always deal with "uplevel" browsers, even for mobile browsers. This was done in page's PreInit event:
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
Page.ClientTarget = "uplevel"
End Sub
So now the mobile version works fine on all tested mobile browsers.
Upvotes: 0
Reputation: 28417
This seems to be a problem relating to browser capability in asp.net. It uses user-agent string to identify a browser and matches it to determine capabilities. The framework lacks enough information for ios and other newer mobile based browsers. I think this has been fixed with ASP.Net v4.5.
Meanwhile you can use this workaround to tell ASP.Net that every (generic) browser supports cookies:
Add a special folder in your project "App_Browsers
". Within this folder create a file named "generic.browser
". Paste the following text in this file:
<browsers>
<browser refID="Mozilla">
<capabilities>
<capability name="xml" value="true" />
<capability name="cookies" value="true" />
</capabilities>
</browser>
</browsers>
Upvotes: 1