HttpHandlers and Classic ASPhttp://forums.asp.net/t/949968.aspx/1?HttpHandlers+and+Classic+ASPTue, 03 Jan 2006 16:04:36 -05009499681155600http://forums.asp.net/p/949968/1155600.aspx/1?HttpHandlers+and+Classic+ASPHttpHandlers and Classic ASP <p>Quick question: Is it possible to insert an http handler into the pipeline&nbsp;for a classic .asp page, so that the .asp page is processed as normal, but you have access to the request and response before and after classic .asp processing? </p> <p>Many thanks</p> <p>James</p> 2005-12-30T19:01:01-05:001155654http://forums.asp.net/p/949968/1155654.aspx/1?Re+HttpHandlers+and+Classic+ASPRe: HttpHandlers and Classic ASP <p>It is not possible to do it the way you describe, which looks like this:</p> <p><font face="Courier New">&nbsp;&nbsp; Request --&gt;&nbsp;&nbsp; Pre-handler&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; Handler&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp; Post-handler&nbsp;&nbsp;&nbsp; --&gt; Response<br> &nbsp;&nbsp; page.asp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; by ASP.NET&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; by ASP&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp; by ASP.NET</font></p> <p>The ASP runtime is an ISAPI executable that the ASP.NET runtime cannot launch. That is, your ASP.NET handler code (maybe an .ashx handler in this situation) cannot create an instance of the ASP runtime and then pass it the original request for processing, and then get hold of the output.</p> <p>What you can do however is have your ASP.NET handler issue a full new web request. Say that you have updated IIS so that requests for .asp extensions are mapped to ASP.NET. You then add a new extension (say .old) which is mapped to ASP. Your ASP.NET handler receives a request for page.asp, and then issues a new web request for the page named page.old, which will be passed by IIS to ASP. Your ASP.NET handler will get the response from ASP. Then, any post-handler processing (such as filtering that HTML response) can occur. This process looks like this:</p> <p><font face="Courier New">&nbsp;&nbsp; Request --&gt;&nbsp;&nbsp; Pre-handler&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; Handler&nbsp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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ----&gt; Request --&gt;&nbsp;&nbsp; Handler&nbsp;&nbsp; --&gt; Response ----<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; page.old&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; by ASP</font></p> <p>To learn how your own ASP.NET handler can issue a new request, please refer to the documentation for the <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemNetWebClientClassTopic.asp"> <strong>WebClient class</strong></a>. While that would be a bit slow&nbsp;(as the user must wait for two requests to be processed), you can cache the result so that this is a one-time-only expensive operation. You could&nbsp;then&nbsp;add a file-dependency to&nbsp;that cached output, so that should the page.old file change, this will remove ASP.NET's cached version of the page. Then,&nbsp;when the page is next requested,&nbsp;ASP.NET goes through the two-request cycle, and again caches the output with a file dependency.</p> <p>Does that help you?<br> &nbsp;<br> &nbsp;</p> 2005-12-30T20:03:03-05:001155807http://forums.asp.net/p/949968/1155807.aspx/1?Re+HttpHandlers+and+Classic+ASPRe: HttpHandlers and Classic ASP <p>Many thanks, I think that is the best response I have ever seen to a question posted on a forum, ever. </p> <p>My situation right now is that I want to apply page caching by&nbsp;storing a classic&nbsp;asp response (and injecting the cached page into the response stream the second time round) much like ASP.NET caching.</p> <p>Am I correct in thinking that by using webclient etc to reissue the response I will loose all the session variables,cookies etc as it is a new request (and from a different client etc) and&nbsp;I would have to map those across to the new session?</p> <p>Many thanks again</p> <p>James</p> 2005-12-31T00:10:06-05:001156182http://forums.asp.net/p/949968/1156182.aspx/1?Re+HttpHandlers+and+Classic+ASPRe: HttpHandlers and Classic ASP <p></p> <blockquote><span class="icon-blockquote"></span> <h4>jameswestgate</h4> Am I correct in thinking that by using webclient etc to reissue the response I will loose all the session variables,cookies etc as it is a new request (and from a different client etc) and&nbsp;I would have to map those across to the new session?</blockquote> I have not had occasion to do this myself, but I will give you my best guess. <p></p> <p>When your ASP.NET handler receives the request for page.asp, the cookie is not a little thing that is somehow &quot;attached&quot; to the original request. (I am not being condescending here, because I <em>do</em> tend to&nbsp;visualise the cookie as an attachment.) Rather, the cookie value is a part of the header information of that request.&nbsp;Now, when your ASP.NET handler prepares the new web request, you do have the option of constructing the header information. That is, your ASP.NET page looks at the header collection of the request for page.asp, and then reconstructs this same information in the web request for page.old. Effectively, it is passing the cookie value on to the ASP handler.</p> <p>In the same way you can&nbsp;inspect form name-value collection of the original request for page.asp, and reconstruct it for the web request for page.old. Further still, you can grab the query string that was attached to the request for page.asp, and add to the request for page.old.</p> <p>That should, I think, be all you need for the ASP handler to think that the incoming request came from the web surfer sitting at her computer, and not reissued from a machine. In this case, all session and other state features should be maintained. The operative phrase there is &quot;I think.&quot; I don't actually know, as I have never had need to do this.</p> <p>However, MSDN has some information on sharing state between an ASP.NET application and an ASP application. The same sections of MSDN may provide additional information on how to get the two environments working together.<br> &nbsp;</p> 2005-12-31T22:33:29-05:001157750http://forums.asp.net/p/949968/1157750.aspx/1?Re+HttpHandlers+and+Classic+ASPRe: HttpHandlers and Classic ASP Many thanks for the response, I think I'm pretty much in the situation that I can just use classic .asp for this purpose, Ill let you know if I find a godd way of doing this with asp.net.<br> <br> Best wishes<br> James<br> 2006-01-03T16:04:36-05:00