views:

31

answers:

1

I am using jQuery within a server side control to post back to a common handler.

For instance, I have "/handler.ashx" which services pages all over my application.

How I want some code within handler.ashx to be able to get the class which created the page that the control is on. In handler.ashx I can see the referer (for example Referer:http://localhost/Playground/form2.aspx). However, I don't know how to use that URL to get the class Playground.Form2.

Ideas:

  1. I could obviously parse the URL and assume that is the class name, but that isn't safe.

  2. I could use reflection to iterate through all classes which extend from Page, and check the TemplateSourceDirectory and/or AppRelativeVirtualPath to see if it is the correct object.

However, I was wondering if there is some method available I can use, or if anyone recommends not going down this road in the first place.

+1  A: 

Rather than trying to get the type object from the Request, it might be better to pass some kind of unique identifier from the page calling the handler which identifies the requesting type. To simplify this process, you can make a static class with a method that accepts the unique identifier and returns a Type object.

Depending on the frequency of retrieving these Type objects, it might be prudent to cache the result of the type reflection.

Nathan Taylor