views:

222

answers:

0

I have a silverlight app, which uses forms authentication for security purpose. I have a custom membership provider to authenticate the user. This is hooked up properly and is working.

Then, after its authenticated I have user information which I need to save (More than just the name), hence I create a custom cookie and save it. All works fine, when its the only browser open in the client side.

But, if the user closes the browser and runs the app again, the app fails. (because the cookie already exists - if I remove cookies and start the app it works). So, couple of questions

1) Am I missing something, my forms authentication ticket looks something like On Application_start

 System.Web.ApplicationServices.AuthenticationService.CreatingCookie
   += new EventHandler<System.Web.ApplicationServices.CreatingCookieEventArgs>
                    (AuthenticationService_CreatingCookie);

 protected void AuthenticationService_CreatingCookie(object sender,
   System.Web.ApplicationServices.CreatingCookieEventArgs e)
 {
    FormsAuthenticationTicket ticket = new
        FormsAuthenticationTicket(1, e.UserName, DateTime.Now,
                 DateTime.Now.AddMinutes(30), false,
                 e.CustomCredential, //I put some custom string data in here
                 FormsAuthentication.FormsCookiePath);
 }

2) How to debug this? Lets say I have cookie in the client side and if I debug, the error comes on the client side after service runs saying "The remote server returned an error: NotFound."

InnerException : {System.Net.WebException: The remote server returned an error: NotFound.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.b__4(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.b__0(Object sendState)}

3) Is there other simpler way to cache this data. I looked at Session alternative, session is not available at Application_AuthenticateRequest(object sender, EventArgs e). And most of the people didnot recommend it. Cache is an option, but needs to be handled differently as a dictionary. I don't want to make database calls to build my custom user identity each time forms authentication calls Application_AuthenticateRequest.