Wrox Programmer Forums
|
BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9
This is the forum to discuss the Wrox book Professional ASP.NET 3.5: In C# and VB by Bill Evjen, Scott Hanselman, Devin Rader; ISBN: 9780470187579
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 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 July 16th, 2010, 01:23 PM
Registered User
 
Join Date: Jul 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default HTTPModule Chapter 27

The example in 27-2 is not working for me.

Has anyone else had trouble getting this code to work.
 
Old July 30th, 2010, 05:36 PM
Registered User
 
Join Date: Jul 2010
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes, I could not get it to work as written - but I did get it to work with two changes:

Instead of using the PreSendRequest event, I used the PostRequestHandlerExecute. And I did not save the context in a private instance variable, instead I explicitly called the HttpContext.Current.Response.Output.Write() method in my event handler.

The code in the book works once, only the first time, in my experience.

Code:
        void context_PostRequestHandlerExecute(Object sender, EventArgs e)
        {
            //alter outgoing request by adding HTML content

            string message = @"<!-- This page has been post processed  at " +
                System.DateTime.Now.ToString() +
                @" by a custom HttpModule. -->";

            HttpContext.Current.Response.Output.Write(message);
         }
The Following User Says Thank You to FrostyMorn For This Useful Post:
robbaralla (August 21st, 2010)
 
Old August 1st, 2010, 07:29 PM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Do you mean the code as exactly in the book only works the first time, or that your modified code only works the first time? Did your modifications correct your problem or are you still having trouble?

HTTP Modules and Handlers are really powerful tools once you get used to working with them, and give you a lot of extra possibilities.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
 
Old August 1st, 2010, 07:46 PM
Registered User
 
Join Date: Jul 2010
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
...Do you mean the code as exactly in the book only works the first time...
Yes.

Quote:
...Did your modifications correct your problem or are you still having trouble?
My code works consistently. The code in the book does not, the problem the OP, sherbug, was having is with the code in the book. A bug, or perhaps some overlooked configuration requirement - I didn't dig into that.
 
Old August 21st, 2010, 02:03 PM
Authorized User
 
Join Date: Apr 2009
Posts: 48
Thanks: 16
Thanked 0 Times in 0 Posts
Default thanks FrostMorn

I had exactly the same problem, the code did not work, not even the first time.
Your change of the PreSendRequestContent event into the PostRequestHandlerExecute event did the trick.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 27: Modules And Handlers - Listing 27.2 Nikhil BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 0 February 4th, 2010 07:25 AM
CHAPTER 2 page 26 -27 joopthecat BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 August 3rd, 2009 07:03 PM
where are the source code for Chapter 27 ? jamesxd BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 1 June 20th, 2008 08:23 AM





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