Dynamically set path in authentication mode
Here is the problem we are facing.
In a hosted environment setup, we host the same project multiple times. We are currently manually specifying the path in the form config section of our web.config. However, in order to smooth our deployment process, we would like to set the Path depending on the name of the virtual directory.
Is there a way for us to dynamically set the Path in the web.config?
a source to share
There is an overload here FormsAuthentication.SetAuthCookie
that takes the cookie path as a parameter, so if you handle the login process yourself, you can simply traverse the path of your choice.
The problem is that the standard System.Web.UI.WebControls.Login
will only use the default path value. However, you might have handled the event LoggedIn
to fix the path ...
void FixCookie( object sender, EventArgs args )
{
Response.Cookies[FormsAuthentication.FormsCookieName].Path = "/my-custom-path";
}
a source to share