Last post May 23, 2007 11:08 AM by albertpascual
May 22, 2007 10:37 PM|DavidKiff|LINK
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:
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,
May 23, 2007 12:47 AM|albertpascual|LINK
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:
May 23, 2007 04:17 AM|rstrahl|LINK
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
Typically Custom Authentication schemes use a module to do this
+++ Rick ---
May 23, 2007 05:40 AM|Svante|LINK
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.
May 23, 2007 10:58 AM|DavidKiff|LINK
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,
May 23, 2007 11:08 AM|albertpascual|LINK
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 ;-)