Michael Flanakin's Web Log

Comments and complaints on software and technology in general

  Home  |   Contact  |   Syndication    |   Login
  159 Posts | 18 Stories | 95 Comments | 530 Trackbacks

News

This weblog is no longer being maintained. For the latest, check out www.michaelflanakin.com!

Article Categories

Archives

Post Categories

Image Galleries

Miscellaneous

Article moved here.

posted on Wednesday, August 04, 2004 1:20 AM

Feedback

# re: Implementing HTTP Handlers in ASP.NET 8/5/2004 9:24 AM David
First, thank you for the research you did, and the mostly clear description of how to get the core functionality of FrontController working in .NET.

I put together some test code based on your observations and the sample code supplied by Microsoft, and have some observations and questions.

Your use of the <AppSettings> section does not have the full path in the key, while I found in my implementation that the full path was produced by the RawUrl property, which gave me a NULL exception.

It appears that to use FrontController, one must specify the target page client-side via javascript, either by specifying the target logical page, or using a hidden variable that the handler uses to direct navigation. This is the only way I know to tell the handler where to go. Am I correct?

When I specify a navigation from the current page to another page, I must do a redirect in the handler, or I will get a viewstate corruption exception. This makes sense because ASP.NET expects a certain viewstate in a page, and is receiving viewstate for a different page. Is this a known issue, or am I missing something?

I am, of course, coming at this (front controller) from a Java perspective and two years with struts, so I have some preconceptions that might be getting in the way. Basically, I am trying to preserve all the features of ASP.NET while gaining Front Controller.

You can email me at dbicking1 at earthlink dot net and/or respond here. Thanks!

David

# re: Implementing HTTP Handlers in ASP.NET 12/9/2004 6:45 AM Craig
Thanks For the help.
It works great.

I wanted to know if you have maybe done the following.

I have a WebForm, and on it I have a PlaceHolder and 2 Buttons.
I have a 2 WebUserControls which are bringing back different data in a Repeater.

I want to associate each of the 2 buttons with the 2 WebUserControls. ie. When I click on Button1 it must place WebUserContol1 on the PlaceHolder. I want to use the HTTPhandler code to control which WebUserControl is created on the PlaceHolder. So if a user types in for example //localhost/MyApp/Data1.aspx it must created the WebForm and place the WebUserControl1 on the PlaceHolder

If you can help me with this I will be extremely greatful.

If you need anymore info please let me know

My email address is : craig.gabriel@ast.co.za

Thanks

Craig

# re: Implementing HTTP Handlers in ASP.NET 12/18/2004 12:48 AM Michael Flanakin
David,
Thanks for pointing out the problem with my appSetting key's not being fully-qualified virtual paths. I originally had all the files (logical and physical) in the same directory and I believe this (along with other issues) allowed this to work.

I'm not sure what you mean when you mention the client-side javascript. If you're talking about the post-back issue, I believe I covered that. If you're talking about linking to random other pages (and this one from other pages) you'll always use your logical URLs. For instance, if you have "/Customer/Flanakin.aspx" going to "/Customer.aspx?ID=123", they you'd just always refer to the "pretty" URL, "/Customer/Flanakin.aspx". Otherwise, I'm not sure what you're asking.


Craig,
So, if I understand correctly, you want to have two logical paths point to the same page; however, you want the page to determine its content based on that. Ok, so if this is right, here's what I would do... (because it's not covered in my article)

Within the handler, add code that will check for whatever conditions you want and add a special value to the context.Items NameValueCollection object. For instance, just do:

context.Items.Add( "FillPlaceHolder", "WebUserControl1" );

Now, this should not be done directly in the handler. It can be, but it's just not a good idea to put all special circumstance situations in the handler. I would suggest extending the config section to allow you to add customizable rules. This goes way above and beyond the scope of this article, but can provide you with an immense, extensible solution based on the Command Pattern.

Hope this helps!

# re: Implementing HTTP Handlers in ASP.NET 1/20/2005 7:01 PM David
Michael,

Thanks for your response - and for notifying me in email about it. Since I wrote my first message, I figured out everything I needed and created a framework I named "Pandora" for our projects at work.

You did not understand my statements quite right though. I didn't want to have two different logical paths go to the same page. I was puzzling out a couple of issues:

1. How to initiate a navigation event. I eventually settled on the fact that I can either instruct navigation through a javascript submit() with an appropriate action (the way I did it in Java/Struts), or use the ASP.NET "postback" and "forward" from there.

2. How to get the javascript submit to another page to work, since I was getting corrupted viewstate errors if I did anything other than "postback". Also, when I tried to "forward" in the handler, I still got the viewstate error because the page tried to load the original page's viewstate. I wanted to avoid "redirect" because it loses Context and restarts the request (thus re-executing code unnecessarilly).

I stumbled upon the overridable viewstate load method and solved the second issue. My handler now determines if the request is a postback, and if it isn't, does not let the page attempt to load Viewstate. I can now use "action objects" to forward to other action objects in the same http request event.

I also added an intercepting filter pattern for extensibility and included base classes for page templates ("tiles" in Struts parlance). I have navigation controlled through "redirect-config.xml". It also loads the intercepting filter command classes and configures a "session monitor" pattern I created.

I'm rather pleased with myself. Your Blog helped mightilly!

David

# front controller for asp.net 1/27/2005 7:59 AM SteveGYCN
Ping Back??:blog.csdn.net

# re: Implementing HTTP Handlers in ASP.NET 2/13/2005 10:21 PM Prashanthan K
Hi:

There are few pages in my project tooks more time to load the data from the backend. My idea is, whenever there is a call to Database, it should execute in seperate thread, not in asp.net worker thread. Is it possible to Implement HTTP Handler in Data Access Layer.

Thanks

Prashanthn K

# re: Implementing HTTP Handlers in ASP.NET 2/27/2005 2:51 AM prashant
Nice article..

# re: Implementing HTTP Handlers in ASP.NET 3/14/2005 6:00 AM smitha
Hi,

I am trying to implement the Front Controller. The senario is I have a "firstPage.aspx" from which some data for Eg "Name and Age" is taken and on a hyperlink click it should add the details to the db.

1. On click of the hyperlink it goes to the handler and from where it finds out which is the class to handle this request.

2. The query is I want to get the values of "Name and Age" in my handling class. Is there any way to add to the Context object. If I am adding as Context.Items("key","Value") in my Firstpage.aspx, it doesn't get added to the Context object which is available in the ProcessRequest(HttpContext Context) of the Handler class.

How can I get the values of the page controls.

# re: Implementing HTTP Handlers in ASP.NET 4/7/2005 10:26 AM Mete
Its all good.
How do i handle the buttons on the page
Once the url get executed by handler how do the handle handles the commands. How do i implement the command and buttons that are are pressed.

thanks
if someone can post here pls

# re: Implementing HTTP Handlers in ASP.NET 4/7/2005 11:48 AM Michael Flanakin
As long as you're handling the post-back problem, then you'll just do what you typically do and create *_OnClick() or (whatever the event is) methods for each control them in the code-behind.

# re: Implementing HTTP Handlers in ASP.NET 4/26/2005 8:56 AM Alex
Hi there,
When I run RewritePath() nothing happen. I suggest that is why
IHttpHandler handler = PageParser.GetCompiledPageInstance(
targetUrl.Substring(0, urlLength), null, context );
handler.ProcessRequest(context);
code in place. But MSDN says that PageParser class should be never used from our code?

Thanks

# re: Implementing HTTP Handlers in ASP.NET 6/16/2005 3:09 PM pepe
Hi there,
how can i get the information in the context.response?.I can get the context.request information but,
example:
in the response the status code is always 200 even when there are problems in the page.
how can i fix this.
sorry for my bad english

# re: Implementing HTTP Handlers in ASP.NET 7/11/2005 7:56 PM Roshawn
<p>Nice article</p>
<p>I just finished reading a similar article on M$ site. There the developer was using regular expressions inside the configuration file.</p>
<p>Your implementation is a lot simpler that the M$ article and many others that I've read. I'm wondering if regular expressions can be used in your implementation as well.</p>

# re: Implementing HTTP Handlers in ASP.NET 7/14/2005 1:29 AM oshaath
Hi there,

Can i associate more than one HttpHandler to the same path (ex. *.xyz) and verb (wx. GET)?

I have files that i want to process them using a custom handler then i want PageHandlerFactory to process them next.

Is it possible?

Thanks on advance.

# re: Implementing HTTP Handlers in ASP.NET 11/8/2005 4:41 AM Michael Flanakin
As far as using regular expressions, you definitely can. What I did for my real implementation was create a custom config section handler that had an attribute that allows for DOS wildcards (? and *) or regex. All it does behind the scenes is convert the wildcards to regex.

# re: Implementing HTTP Handlers in ASP.NET 12/7/2005 5:31 AM Lokesh Kumar
Thanks for such a nice description.

# re: Implementing HTTP Handlers in ASP.NET 2/9/2006 8:17 AM Aaron
Thanks for the great article. I am using a httphandler to intercept .aspx files in a CMS app we created so as to use page templates for content. So far it appears to work great.

However, we ran across one issue with an app on the site that is a virtual directory and it's own application. Being that it is segmented off I assumed it would ignore the handler that was placed off the root. Unforunately it is erroring because it cannot find the DLL off the root that contains the handler code. Being that this sub app is its own application it makes sense that it would not have access to the dll off the root.

I've tried various things to get this to work and have seen different behaviour between framework 1.1 and 2.0. I've overrode the handler for that virtual directory so that it used the standard pagefactory but it still errors.

The only way to fix this so that it works in 1.1 is to place the root DLL in the sub applications bin folder then to override the handler in the sub apps web.config to use the standard pagefactory for .aspx pages.

Has anyone run across this before?

# re: Implementing HTTP Handlers in ASP.NET 2/9/2006 9:19 AM Michael Flanakin
I've heard about this issue before, but it was applied to something different - not handlers. The work-around is to reset any settings in the web.config file so the parent app's settings aren cleared out. I believe you need the following:

<httpHandlers>
<clear />
</httpHandlers>

# re: Implementing HTTP Handlers in ASP.NET 2/9/2006 12:16 PM Aaron
I tried that. There appears to be a bug in .NET 1.1 with eventHandlers. When I convert the applications virtual directory to 2.0 then this works.

# re: Implementing HTTP Handlers in ASP.NET 2/16/2006 9:30 PM Kay
Hi,
I want to write a HTTP handler to download file in the form of binary data. How can I do that? What is the best way to do that?

Thanks in advance,
Kay

# re: Implementing HTTP Handlers in ASP.NET 2/16/2006 9:44 PM Michael Flanakin
You don't need an HTTP handler for this. You simply need to change the content type and write the binary data using the Response object.

# re: Implementing HTTP Handlers in ASP.NET 2/16/2006 10:27 PM Kay
Yes thats true. But to avoid blocking of other web service calls after the call to download large binary data, I want to do this using a HTTP handler.So which is the best possible way to do that?

# re: Implementing HTTP Handlers in ASP.NET 2/17/2006 8:10 AM Michael Flanakin
Any code you can put in a handler, you can put in the page request. Maybe you should consider a module. You could validate the request based on request settings, if you need this for more than one page. I honestly just don't think that a handler would be the best option.

# re: Implementing HTTP Handlers in ASP.NET 6/1/2006 8:44 AM Claudio
Hi,

I tried your code and it works well. However, do you know if it is possible to not show any URL at all yet still go to a specific place?
Example: it will always remain at http://somesite/Default.aspx



# re: Implementing HTTP Handlers in ASP.NET 7/7/2006 8:16 AM Kaycey
help with httphandlers;

Scenario:

I have implemented a http handler to present the user with user-friendly Url's in my app. I use the handler to provide navigation from one page to another. I need this to be a server transfer because I need the page to expire if the user hits the back button in his browser. With a redirect I could do the navigation but the page expiration functionality is lost because a redirect is done using the GET method, rather than the POST.

Whn using server transfer i get the inevitable "Error executing child request for >>>" error. I cannot move the files to a diff directory as the application is used /shared by other apps in the same arena.

Any help would be greatly appreciated.

thanks,
Kaycey

# re: Implementing HTTP Handlers in ASP.NET 7/8/2006 3:41 AM Michael Flanakin
If your purpose is URL beautification, the redirect method isn't really feasible because the URLs are still in their original format to the user -- they merely type a "prettier" URL on the initial request. I'm not sure I follow you with the GET/POST issue. Redirects will be GET requests, of course. Transfers will be whatever the request started as, whether GET or POST. The only factor that I remember being a problem with transfers is the fact that you can only transfer within the same application. If you're trying to change the URL to one that points to an application that just happens to be in a child directory, it won't work. There's really no way to do this without using a proxy.

I wouldn't You never want to do a redirect when implementing a handler. If you do, you'll be decreasing performance.
As far as the user's history is concerned, I don't believe the redirect and transfer methods are treated differently. Remember that using Server.Transfer requires the new

# re: Implementing HTTP Handlers in ASP.NET 7/10/2006 8:50 AM KayCey
hi Micheal,

thnx for your response, but i am not sure if you understood my scenario right. I use the http handler to provide navigation in my app as well.

so the user is redirected to an aspx file (which i pass through the handler to mask the original url and query string and use context.rewrite to make it appear more user friendly).

now i am not able to use server.transfer here because of the view state problem between the redirecting page and the redirected page.

Hope this explains the situation better..

thanks,
KayCey.

# re: Implementing HTTP Handlers in ASP.NET 7/10/2006 4:22 PM Michael Flanakin
You fix the view-state problem by using an action-less form, discussed in the Handling Post-Back section.

# re: Implementing HTTP Handlers in ASP.NET 7/12/2006 9:58 AM kaycee
hi Micheal,

using an actionless form did not fix my problem either. Here's what im doing.

1. request comes in for a page say login.aspx - > handler redirects it to login.nice (with a custom file extension)
2. from login.nice user fills out his info and presses a next button - > app then resolves the next page and redirects the user to 2ndpage.nice(again passing through the handler)
3. flow goes on so forth in the application.( so next user goes to 3rdpage.nice ...etc)

this is the flow of the app, instead of doing redirects at everypage is where i want to implement server.transfer. Because from page 2(2ndpage.nice) if the user hits the
browser back button i want the page to expire. This is not possible whn i use redirect. If i do a server.transfer it works but during the course of navigation i get the
"Error executing child request error".

all request for *.aspx and *.nice are configured to pass through my custom httphandler.

This is kind of a real spot for me because i want to hide the ugly urls in the application with the nice custom url's without any querystring values.

do u have any suggestions as to wht i need to do fix the error im currently facing?


i have tried :

1. actionless form.
2. disabling view state
3. trying to pass viewstate through code between the pages etc.

nothing works..! and im not sure wht i can do to fix this.

thanks,
Kaycee

# re: Implementing HTTP Handlers in ASP.NET 8/12/2006 11:18 PM Anand Sah
This is a great article and help us to know depth of HttpHandlers in ASP.NET.
Thanks

# re: Implementing HTTP Handlers in ASP.NET 8/22/2006 12:30 AM Web Design Delhi
The articles about the how ASP.NET process any file extension using HTTP Handlers in runtime environment.

# re: Implementing HTTP Handlers in ASP.NET 11/6/2006 3:25 PM RikB
I am trying yo decide if HTTP Handlers are the way to go in my App. I have several years of experience in .Net mainly in Windows clients and I am new to ASP.NET. My application pages reference a common javascript, let's call it doJava, which attempts to retrieve an instance of an object in the DOM. This i can provide through adding an object with<object>. Where I have a question is that my new object, let's call it newObj, needs to communicate with my web server to pass data back and forth. This activity is initiated by the a function in the doJava script which calls a function in the newObj. The data transfer is not visable to the web page. The newObj method will speak to the server and then wait for a response from the server.
Does this sound like something Http Handlers can do?

# re: Implementing HTTP Handlers in ASP.NET 4/27/2007 5:33 AM development web
Trying to build a http-handler in .net which map static
adresses to an asp(x) page. Example webform1.html is actually a request to webform1.asp or webform1.aspx

aspx works fine but if i try asp i get the following
error: This type of page is not served Description: The type of page you have requested is not served because
it has been explicitly forbidden. The extension '.asp' may
be incorrect. Please review the URL below and make sure that
it is spelled correctly.

This is fixed by removing the following in machine.config
httpHandlers <add verb="*" path="*.asp"
type="System.Web.HttpForbiddenHandler"/>
Now my asp-file is displayed by adressing html-file in a
browser.
HOWEVER: This asp-file is not executed by asp.dll even the
asp-extenstion points to asp.dll in IIS. So my source-code
is displayed in a browser.
Any help is appreciated




# re: Implementing HTTP Handlers in ASP.NET 7/5/2007 2:28 PM Taliesin
Its better to use an ISAPI filter which rewrites the requests. I would recommend :
http://www.isapirewrite.com/

And there is a free version!

# re: Implementing HTTP Handlers in ASP.NET 12/6/2007 4:43 AM Pranu
This is a very good article.It has helped me a lot.
Thanks.

# re: Implementing HTTP Handlers in ASP.NET 4/8/2008 6:07 AM Sai BPO Services (UK) Ltd
very informative in Web development and designing.
Thanks

# re: Implementing HTTP Handlers in ASP.NET 7/1/2008 9:45 AM Deb Web Designer
Nice and really long post and comment, I know little about the .net but when I go to optimize the website with .net extension some issue are there - I can't set an error page in the website.
can any one help me.

Thanks
Deb

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 8 and 4 and type the answer here: