asp.net mvc - Changes to cookie domain for outgoing responses ignored for ServiceStack requests -


i have multi-tenant website (e.g. several different sites, each it's own domain, in same project, separated using mvc areas), authentication cookie has domain manually set when user logs in available subdomains (but not various other sites in project, not sso).

so user logins x.foo.com, cookie domain set foo.com, works @ y.foo.com , z.foo.com. however, because of other domains being served same project auth cookie domain cannot set in web.config in usual manner, instead set manually when user logins in so:

public httpcookie getauthenticationcookie(string username) {     var cookiedomain = urlhelper.gettopandsecondleveldomain();     var authenticationcookie = formsauthentication.getauthcookie(username, false);     authenticationcookie.domain = cookiedomain;     return authenticationcookie; } 

this works fine, of course can cause problem when cookie automatically refreshed sliding expiration. have http module hooked postrequesthandlerexecute event of our mvc app auth cookies set response during request, , overriding domain:

public class authenticationcookiedomaininterceptormodule : ihttpmodule {     public void init(httpapplication context)     {         context.postrequesthandlerexecute += updateauthenticationcookieexpiry;     }      private void updateauthenticationcookieexpiry(object sender, eventargs e)     {         var app = (httpapplication) sender;         var cookiedomain = urlhelper.gettopandsecondleveldomain();          var authenticationcookie = getcookiefromresponse(app.context.response, formsauthentication.formscookiename);          if (authenticationcookie != null)         {             if (authenticationcookie.domain == null || !string.equals(authenticationcookie.domain, cookiedomain, stringcomparison.invariantcultureignorecase))             {                 authenticationcookie.domain = cookiedomain;             }         }     }      private httpcookie getcookiefromresponse(httpresponse response, string cookiename)     {         var cookies = response.cookies;         (var = 0; < cookies.count; i++) {             if (cookies[i].name == cookiename)             {                 return cookies[i];             }         }         return null;     }     } 

this works fine unless request our servicestack front end use handle our ajax requests. in case module fires normal, picks cookie if been set, changes domain should, when response sent client changes cookie ignored.

is there reason why cookie changes wouldn't saved response in scenario? guess fact servicestack uses httphandler hook in request cycle in first place, not going through normal mvc request life-cycle.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -