By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,313 Members | 1,145 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,313 IT Pros & Developers. It's quick & easy.

Authorization cookie not valid for subdomains ?

P: n/a
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,_passwor d))
{
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 ?

Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

<cr************@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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,_passwor d))
{
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 ?

Nov 19 '05 #2

P: n/a
Thanks, that worked!

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.