Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 25th, 2010, 08:48 AM
Authorized User
 
Join Date: Jan 2010
Posts: 14
Thanks: 4
Thanked 1 Time in 1 Post
Default Cookies ch6 p222-224

Hi Imar,

Following the code for inserting and defining cookies, (which, of course does work OK), and in the process of testing my own competence I made a typo in defining the values in the DDL in MasterPage/Master, which should have included the line:

Code:
<div id="SideBar">Select a Theme
        <asp:DropDownList ID="lstPreferredTheme" runat="server" AutoPostBack="True" 
          onselectedindexchanged="lstPreferredTheme_SelectedIndexChanged">
          ...
          <asp:ListItem>DarkGrey</asp:ListItem>            
          ...
        </asp:DropDownList>
</div>
Being less than careful in entering the line I inadvertently entered

Code:
 ...
          <asp:ListItem>Dark Grey</asp:ListItem>            
...
with the embedded space. Stupid, yes! Careless, yes! However, as this forced me into error mode as the 'Dark Grey' theme did not exist I had to remove the cookie to continue. I achieved this by drilling into
%userprofile%\AppData\Roaming\Microsoft\Windows\Co okies\Low and deleting the specific cookie. This was more of a chore than an inconvenience, but later I did further checking and found that if I changed the code in MasterPage.master.cs from

Code:
protected void lstPreferredTheme_SelectedIndexChanged(object sender, EventArgs e)
    {
     ...
      preferredTheme.Expires = DateTime.Now.AddMonths(3);
     ...
    }
to
Code:
...
      preferredTheme.Expires = DateTime.Now.AddDays(-1);
...
I could clear the cookie instantly.

I wonder if it may be worth adding some clarification in future editions to provide a more elegant method of killing an invalid, or incorrect cookie. For all of the usual reasons I would have been loathe to clear all cookies, (something of an overkill in this case), and I have no real issues with drilling down, but perhaps the programmatic method is both 'safer' and perhaps more elegant.

There again, I suspect that not many people will run into this issue anyway.
__________________
Alan.
 
Old January 25th, 2010, 03:55 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yes, good suggestion. I am indeed doing something like this in my new book, based on some earlier reports.

One solution is to use a Try / Catch block where you try to set the theme based on the cookie, and delete the cookie when the code crashes somehow. Using the Expires property is indeed the way to remove the cookie.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
Alanrf (January 26th, 2010)





Similar Threads
Thread Thread Starter Forum Replies Last Post
ch6 Skins and Named Skins wingri BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 April 8th, 2008 02:57 AM
Anybody find the missing code in ch6? nickolas BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 January 29th, 2006 10:38 AM
Error: movie.php & commit.php on p182-186, ch6 willburke BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 12th, 2004 02:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.