Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Security / January 2005

Tip: Looking for answers? Try searching our database.

Cookie not persisted w/o call to GetRedirectUrl()

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim Foye - 27 Jan 2005 03:24 GMT
I am using forms authentication. I do not have default.aspx nor do I want
one as I am using multiple roles and I want to redirect the user after
logging in based on his role. Here's the pertinent section from web.config:

<authentication mode="Forms">
   <forms name="MMAuth"
     loginUrl="/forms/cl_signin.aspx"
     protection="All"
     timeout="60"
     path="/">
   </forms>
</authentication>
<authorization>
   <deny users="?" />
   <allow users="*" />
</authorization>

The below code is not my real code, but is an example I lifted from a
website, and it should serve to pretty well illustrate my problem. I put
into my source and compiled and debugged it. Email is a textbox with the
user's email which serves as his user name, and let's say I've already
validated him.

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1,
                                                                           
                            Email.Text,
                                                                           
                            DateTime.Now,
                                                                           
                            DateTime.Now.AddHours(3),  // or anything else,
it doesn't matter
                                                                           
                            true,
                                                                           
                           "client");
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,
encryptedTicket);
cookie.Expires = ticket.Expiration;  // or anything else, it doesn't matter
Response.Cookies.Add(cookie);
Response.Redirect(FormsAuthentication.GetRedirectUrl(Email.Text, true));

This will persist the cookie, but I can't use this code, because
GetRedirectUrl() is a bit stubborn and only wants to take me to
default.aspx. According to ASP.NET Cookbook by O'Reilly, no problem, I just
call Response.Redirect() with the page I want to go to. That will persist
the cookie. But it doesn't.

I find it very strange that I have to

1) Set an expiration on the ticket
2) Tell the ticket that is persistent
3) Set the expiration for the cookie that contains the ticket

and still the cookie does not persist. It seems to come back from the
browser for the current session, but it won't persist. It will only persist
if I

4) call GetRedirectUrl() with the 2nd parameter set to true to let it know
that the cookie (whose expiration I have set) which contains the ticket
(whose expiration AND persistence flag I have set) should in fact be
persisted on the client.

Calling GetRedirectUrl() and tossing the return value and going on my merry
way with Response.Redirect(), while looking very funky, would be acceptable
at this point, but that does not work, I have to call it exactly as you see
above.

This is a strange API, even by Microsoft standards.

Please help.

Jim
Jim Foye - 30 Jan 2005 17:06 GMT
Does anyone have any ideas??

>I am using forms authentication. I do not have default.aspx nor do I want
>one as I am using multiple roles and I want to redirect the user after
[quoted text clipped - 69 lines]
>
> Jim

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.