locked
ASP.NET Handlers (.ASHX) RRS feed

  • Question

  • User1186257875 posted

    Hi,
    I am very new to HTTP Handlers.  My application has a method for checking authentication.  I would like an HTTP handler to create a new instance of my custom authentication class and call the apropriate method.

    When I compile the handler I run into problems because it is dependent on my class.  My class is only compiled at runtime, so i am not sure what to do.  I want the handler to run on every request to an ASP.NET page. 

     I assumed i could add the handler.ashx file to the App_code folder and add a reference to the web.config file:
    <httpHandlers>
    <
    add path="*.aspx" verb="*" type="MyHander.Handler"/>
    </
    httpHandlers>
    But this complains "Could not load type 'MyHander.Handler'."

    If you have any better ideas then please let me know!  At the moment its running on the masterpages code behind and works as i expect- just would like to do things properly!

    Thanks in advance,
    David Kiff
    http://davidkiff.co.uk

    Tuesday, May 22, 2007 10:37 PM

Answers

All replies

  • User1001868398 posted

    Ok, if you create an ashx file, you do not need to register the handler on the web.config, only if you create a class or a library, just call the handler without even compiling it, you may find more info here: http://alpascual.com/blog/al/archive/2006/06/19/Http-Module-Skeleton-.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 23, 2007 12:47 AM
  • User1622957740 posted

    Hmmm... it sounds to me what you really want is not a handler but a module. Handlers are an endpoint (like ASPX pages or ASMX Web services for example) - modules plug into the ASP.NET pipeline and can 'listen' to specific URLs and act on them as part of the pipeline.

    Typically Custom Authentication schemes use a module to do this

     +++ Rick ---

    Wednesday, May 23, 2007 4:17 AM
  • User-225114762 posted

    There are several issues here (one of the simpler ones: Is the name really MyHander.Handler ? MyHandler.Handler sounds more likely). You cannot drop the .ashx file into App_Code and refer to it like that, because the assembly generated from code in App_Code is not found. The assembly needs to be in the bin folder or the GAC.

    However, I see several problems. First of all, I do not think that you want a HttpHandler for your custom authentication. I think you want to implement your logic in the Application_Authenticate method in Global.asax. If you really want to you can hook the individual events availble via HttpApplicaition, or implement a HttpModule that hooks these events.

    To do this via a HttpHandler probably requires more work than you want, and it does not appear to be the way to go as far as I can determine from your description.

    Wednesday, May 23, 2007 5:40 AM
  • User1186257875 posted

    Ahh ok, I was assuming a HTTP handler can handle all incomming requests, rather than being an endpoint.  Its seems silly calling it a HTTP Handler if it is essencially a file that produces an output/task and does not handle all HTTP requests/responses!?

    It sounds (as you suggested) i need a HTTP Module?  What I would also like to do is grab the incomming session id, check it has not been "killed" (Marked in SQL Server- another story) and then allow the request to continue,  If the session ID has been marked as "killed" then i would like to call my logout method in a different class and redirect them to a login page.

    So I will need a method for handling any request to a resource, such as an .aspx file, rather than a single endpoint.

    I will research into modules further,

    Thanks

    Wednesday, May 23, 2007 10:58 AM
  • User1001868398 posted

    Let us know what approche do you take. I believe the HttpHandler or a Module is what you need. However I am not hte guy desihing the syste ;-)

    good luck

    Wednesday, May 23, 2007 11:08 AM