Authorization cookie not valid for subdomains ?

C

craigkenisston

Hi,

I create a one day ticket in my authentication code like this :

private void btnLogin_Click(object sender, System.EventArgs e)
{

string _userId = txtUserId.Text;
string _password = txtPassword.Text;

if (FormsAuthentication.Authenticate(_userId,_password))
{
FormsAuthentication.RedirectFromLoginPage(_userId,false);
FormsAuthenticationTicket authTkt = new FormsAuthenticationTicket(1,
"mycookie", DateTime.Now, DateTime.Now.AddDays(1), true, _userId);
HttpCookie authCookie = new
HttpCookie(FormsAuthentication.FormsCookieName);
authCookie.Value = FormsAuthentication.Encrypt(authTkt);
authCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(authCookie);
}

}


Recently I added some subdomains to my site and I realize that the
authorization is not valid there, i.e. the user appears as not logged
in.
How can I make an authorization ticket valid for all the domain and its
subdomains ?
 
R

RCS

authCookie.Domain = "mydomain.com";

That will make the cookie valid for any subdomain within mydomain.com

To be safe, you may want to do:

authCookie.Path = "/";

too - that makes the cookie valid for any directory within the site too...

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top