Tony Testa posted on September 19, 2007 00:00
I stumbled onto this today while doing my daily rounds of the .NET sites.  Microsoft has a new product that just released a CTP called "Astoria". 

Here is a description from the "Astoria" website :
"Astoria is a project in the Data Programmability team at Microsoft that explores how to provide infrastructure and tools for exposing and consuming data in the web. Astoria can create data services that are exposed in a natural way to the web, over HTTP and using URIs to refer to pieces of data; these data services can be consumed by AJAX front-ends, Silverlight-enabled web pages, desktop applications and more. At this time we’re making available two experimental elements of project Astoria: the Microsoft Codename Astoria toolkit and the Microsoft Codename Astoria online service."

From what I can gather this technology will really fit well with SOA by exposing the data as a service.  In addition it seems like this will help make consuming data through AJAX easier.  You could essentially create the data service for your customer data for example and have it available to all your WebApps and desktop apps in your organization.  This way with all your apps your not essentially creating a data access layer for each app, instead you would just consume this data service.

Check out the Project Astoria Team blog here
Also check out a sandbox they've created to showcase the technology as well as let you create your own data services to play  with.  The encarta sample is kind of cool and gives a good example of how your could use this technology.

When i finally get around to it and create a .NET 3.0/3.5 sandbox for myself, i'll certainly give this a try.

Posted in:   Tags: , ,
Tony Testa posted on September 19, 2007 00:00
What is an HttpHandler?
It is the earliest point where you have access to a request that is made to IIS.  In a typical application, a user calls .aspx pages, which maps to an HttpHandler, that handler is the PageHandlerFactory.  An HttpHandler is just like an aspx page except it doesn't have all of the UI elements therefore it doesn't have to process them.  HttpHandlers are therefore more reusable.  

Why would you want to use an HttpHandler?
Some great examples of why you would want to use an HttpHandler is in the case when you want to return an image from the database.  You could create an HttpHandler to call the database and return the Image.  Typically I used to create a page for this and override the response type to return the image.  With an HttpHandler, you can skip all the extra page processing and just return the image.
Another great example is when you want to download a file, such as a an excel file.  You could pass in a datatable, convert it, and then return it as an excel file.  Again, I used to create a page for this and override the response content types to do this, but an HttpHandler is a far better solution to the problem.

Real-World Examples
A real world example is on the blog engine I am using to write this post, SubText.  It uses a custom HttpHandler to map URL's to controls.
Another GREAT example is the Microsoft AJAX framework.  If you look at the base web.config file they give you.  See below for an extract of the <httpHandlers> section :

   34         <httpHandlers>
   35             <remove verb="*" path="*.asmx"/>
   36             <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
   37             <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
   38             <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
   39         </httpHandlers>

As you can see, a few custom file extensions are mapped to HttpHandlers.  This is how the Microsoft AJAX framework does most of the heavy lifting for you.  The HttpHandlers that are included handle inserting the necessary scripts into the page to perform the AJAX requests.

Demo
I made up a demo solution to show the basics of creating a HttpHandler.  Whats in the demo is 3 examples.  The first example is just a basic HttpHandler.  What it does when called is just return some basic text to the browser.  The second example shows creating a simple datatable and exporting it as tab delimited excel file.  The third example shows a more useful example where we call a database and export the results as a tab delimited excel file.

The real key to the HttpHandlers, besides implementing the interface, is adding the directives in the web.config file.

    1 <?xml version="1.0"?>
    2 <configuration>
    3     <appSettings />
    4     <connectionStrings/>
    5     <system.web>
    6         <compilation debug="true" />
    7         <authentication mode="Windows" />
    8 
    9         <!-- add this under the <system.web> -->
   10         <httpHandlers>
   11             <!-- you could specify a wildcard with a extension, or a specific name of a "page" to call -->
   12             <!-- you can also create an extension of your choosing, and tell IIS to process your extension as a handler -->
   13             <!-- <add verb="*" path="*.ashx" type="BasicHelloWorldHandler"/> -->
   14             <add verb="*" path="BasicExport.ashx" type="ExportToExcelHandler"/>
   15             <add verb="*" path="ExportDB.ashx" type="ExportToExcelDBHandler"/>
   16         </httpHandlers>
   17     </system.web>
   18 </configuration>

The above web.config file has commented out code which shows that we can map any file with the extension .ashx .  The other two <add> elements in the <httpHandlers> section shows how we can map a specific filename to the HttpHandlers we wrote.  As you can see, you pass in to parts, the "Path" which is the filename to map, and the "Type" which is the class to map the call to the filename to.

Download Files
You can download the demo solution here.
Its a website project, so create a directory for it, and extract the files there.  Then create a virtual directory for it in IIS or just run it in VisualStudio2005.

Posted in:   Tags: ,
Tony Testa posted on September 18, 2007 00:00

Nothing really "new" here, but i've included some links about the ASP.NET Application/Page LifeCycle.  I know every so often I have to refer to these...so if anything they will just serve as a personal reference point.

ASP.NET FULL (Application,Page,Control) LifeCycle (.NET 2.0)

ASP.NET Application LifeCycle (.NET 3.0)

ASP.NET Application LifeCycle (.NET 2.0)

ASP.NET Page LifeCycle (.NET 3.0)

ASP.NET Page LifeCycle (.NET 2.0)

ASP.NET Page LifeCycle Poster (.NET 2.0)

ASP.NET Page LifeCycle (.NET 1.1)

ASP.NET Control LifeCycle (.NET 1.1)

ASP.NET WebPart LifeCycle (.NET 3.0)

ASP.NET WebPart LifeCycle (.NET 2.0)

ASP.NET AJAX Client LifeCycle (.NET 2.0)


Posted in:   Tags:
Tony Testa posted on September 16, 2007 00:00

I spoke at the Philly.NET Code Camp 2007.2 yesterday.  It was a good code camp, lots of different sessions to suite all tastes.  They also annouced that Philly.NET is now incorporated, so that they can collect more money and put on more of these events.

I spoke at 1:30 on ASP.NET AJAX.  I felt it went pretty well.  Not as good as I would have liked, but its really only my second talk at an event like this, so i feel i did pretty good.  I do see some room for personal improvement on these speechs so I hope for my next talk that I'll take into account those improvements and give an even better speech.  I even managed to squeek a Sharepoint AJAX-Enabled webpart demo into the presentation.

You can find my presentation here.

The event was really well run.  You could tell the imporvements from last time (not that the last one was by any means bad).  Plus this time i didn't find out that i needed to bring a shit load of breakfast food @ 5PM the day before.

I attended the following sessions as well  :

Tony Lombardo - Advanced Tips for ASP.NET Developers

David Mann - ASP.NET Providers in SharePoint 2007

Miguel Castro - Recruiters: the Good, the Bad, & the Ugly

All were good, but Miguel Castro's was by far the best.  The content had no programming what so ever but it was just well done.  I think i could learn a lot from Miguel about doing these talks.


Posted in:   Tags: , ,
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2017 Tony Testa's World