Results 1 to 5 of 5

Thread: Using HttpHandler and Reflection

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091

    Question Using HttpHandler and Reflection

    I have another ongoing thread regarding this topic, but I think it was getting a little messy and lost, so I thought I start another one focusing more on the remaining issues.

    I have created a custom HttpHandler which handles processing of web requests. This will be utilized by end user developers. They will include my handler dll in their ASP.NET project. The structure would look something like:

    Code:
    Solution 'WebApp1'
         WebApp1
              App_Code
                    Class1.vb
              bin
                    HttpHandler.dll
    "Class1.vb" is the developer's own class, and "HttpHandler.dll" is my class that they are referencing.

    My HttpHandler class contains an attribute called "CustomAttribute". The user's Class1 needs to decorate any subs/functions they want exposed to my HttpHandler class with CustomAttribute.

    This is where I'm a little lost. I need to make use of Reflection to get a list of all subs/functions in the user's Class1 and determine if they are decorated with "CustomAttribute". There is some debate as to whether or not I the user has to inherit from my class. I need to be able to call this line of code on the user's Class1:

    Code:
    Dim methods As MethodInfo() = Me.GetType.GetMethods
    BUT, I will obviously not know what name the user gave their class. So I need to somehow replace the "me" in the above code with, their class name. But how can I do this without knowing their class name? They can also have many classes so I need to somehow find all of their class and iterate over all their methods.

    Any help would be greatly appreciated.

    Visual Studio 2010

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Using HttpHandler and Reflection

    Hey,

    If I am not mistaken, I think this will cover it:

    http://www.codeproject.com/KB/aspnet...alization.aspx

    Also, if you are finished in your other thread, you really should mark it resolved, and specify that the discussion has moved to here.

    Gary

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091

    Re: Using HttpHandler and Reflection

    Thanks gep13. I have marked my other post as Resolved with a link back to this one. I will take a look at the link you provided and let you know how it goes.

    Visual Studio 2010

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Using HttpHandler and Reflection

    Hey,

    Sounds like a plan! Hopefully it will have what you are looking for

    Gary

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Using HttpHandler and Reflection

    Since the methods can be anywhere, you start by enumerating all of the classes in the assembly. You then loop through the methods in each class. You can use Assembly.Load for this. However, you need to know which assembly you're going to be looking at, so you need to either:

    1) get the developers to tell you this.
    2) Forget Assembly.Load and use Assembly.GetExecutingAssembly instead which also gives you a reference to the assembly.

    Once you have the assembly, find its classes. To do this, loop through its Assembly.GetTypes. This is where your code finally comes in.

    vb Code:
    1. Dim methods As MethodInfo() = t.GetMethods()

    Where t is the iterator in your GetTypes loop.

    Then look for your methods.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width