Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

FormsAuthenticationTicket  userdata empty

Posted on 2008-06-24
4
Medium Priority
?
3,213 Views
Last Modified: 2008-07-03
hi all, i am using FormsAuthenticationTicket  
add the cookie in login.aspx

but when i want to retrieve the cookie from default.aspx
the userdata is empty

but the userdata appears again when i close my browser and open it again

any idea on this?

thanks a lot!
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, "myname",
         DateTime.Now, DateTime.Now.AddMinutes(dCookieLife), true, "my_role", FormsAuthentication.FormsCookiePath);
        string ticketEncrypted = FormsAuthentication.Encrypt(ticket);
        HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticketEncrypted);
        authCookie.HttpOnly = true;
        authCookie.Path = FormsAuthentication.FormsCookiePath;
        authCookie.Domain = myHKJCCookieDomainName;
        authCookie.Expires = ticket.Expiration;
        HttpContext.Current.Response.Cookies.Add(authCookie););        
         Response.Redirect("default.aspx");   
        }
 
 
in default.aspx
 
if (Request.Cookies[".ASPXAUTH"] != null)
        {
            try
            {
                FormsAuthenticationTicket ticket1 = FormsAuthentication.Decrypt(Request.Cookies[".ASPXAUTH"].Value);
                Response.Write("UserData: " + ticket1.UserData+ "<br>");
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }

Open in new window

0
Comment
Question by:orbulat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 

Expert Comment

by:nkiran4u
ID: 21863035
i suggest u to use sessions instead of cookies(since session will not expire until the browser window is closed)......

at the same time write the request.cookies in  IfNotpostback  function

if possible post ur entire code and ill try to help u....... also do u just want to display the username in remaining pages when the user is logged in (or) do u want to retreive the saved password(ie if u have checked remember me option wile loggin in (or) do u want to check the encrypted password of the user with the database....
0
 
LVL 10

Author Comment

by:orbulat
ID: 21863064
i can't use session my case

in fact i want to retrieve the userData which holds the role

it's weird that,
1. clear cookie
2. go to logon page (form cookie is written here)
3. user is authenticated
4. redirect to default.aspx (using response.redirect)
5. userdata can't be retrieved, it's empty
6. close browser
7. open browser, go to default.aspx
8. userdata can be retrieved

the above code is for testing to see why userdata can't be retrieved immediately after writing in logon page
0
 
LVL 10

Author Comment

by:orbulat
ID: 21863079
and i just looked at the ticket name

first time login

FormsAuthenticationTicket ticket1 = FormsAuthentication.Decrypt(Request.Cookies[".ASPXAUTH"].Value);

ticket1.Name --> it's sth. like guid

but when i close browser and logon again
the ticket name becomes "myname"

any ideas?

thanks!
0
 
LVL 10

Accepted Solution

by:
orbulat earned 0 total points
ID: 21863910
thanks a lot!

i have sorted out the problem myself

it turned out that there is someone who has added another piece of code somewhere in the global page, which also add a formauthenication cookie, it overrides the correct one!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question