views:

153

answers:

1

Here's the problem we facing.

In a hosted environment setup, we're hosting the same project multiple times. We currently manually specify a Path in the forms config section of our web.config. However, to smooth out our deployment process, we'd like to set the Path depending on the Virtual Directory name.

Is there a way for us to dynamically set the Path in the web.config?

+1  A: 

There's an overload of FormsAuthentication.SetAuthCookie that takes the cookie path as a parameter, so if you're handling the login process yourself then you can just pass the path of your choice.

The problem is that the standard System.Web.UI.WebControls.Login will only use the default path value. You could, however, handle the LoggedIn event to fix the path...

void FixCookie( object sender, EventArgs args )
{
    Response.Cookies[FormsAuthentication.FormsCookieName].Path = "/my-custom-path";
}
stevemegson
I will test this in the morning when I get to work, thanks a mil!
FailBoy
although that works, I found a slightly better solution that I've posted about here: http://www.failboy.net/2009/05/set-forms-authentication-path/
FailBoy