Dan Mackey On ColdFusion Development

ColdFusion, Java, .NET, AJAX, DHTML development and general programming. Daniel is owner and Administrator of CFTagStore.com and works for an Application Development Company in Ireland called Digital Crew. His interests cover all areas of programming in multiple languages with a particular interest in Internet Technologies.

All Articles tagged : Useful Tips
2009-08-09 22:10:00.0

Adobe AIR Flex 3 HTTP Basic Authentication

I am a week into Flex 3 development building an AIR app to test the new API for Teamwork Project Manager and thought I would share an issue with HTTP Basic Authentication that I ran into.

To be honest it has been itching away at me all day today and half of yesterday and I finally solved it.

What I am trying to do:

  • Connect to the Teamworkpm.net API
  • Pass my URL, Username and Password to be authenticated
  • Catch the HTTP Status code in the response
  • Catch any IO errors if the URL can't be found
  • Catch an authorization failure for the credentials passed.
  • Use the URLLoader class in Flex 3

Sounds easy doesn't it? Well, I got everything working fine and then hit a snag. If the credentials passed did not authenticate, then the ugly browser Login dialog appeared right in my beautiful AIR app. I tried everything and eventually even re-wrote the whole thing TWICE using 2 Google Code projects for AS3 HTTP Client calls.

How I did it

I decided to scrap it all and start again. This is how I got it working.

  1. I need to send the login credentials to the server but there was no native method to do this. You need to push an authorization header into the Request Header in base64
    • import mx.utils.Base64Encoder;
    • var loader:URLLoader = new URLLoader();
      var req:URLRequest = new URLRequest(cURL);
      var headerRequests:Array = new Array(1);
      req.method="get";

      var headerRequests:Array = new Array(1);
      var encoder64:Base64Encoder = new Base64Encoder();
      encoder64.encode(cUsername + ":" + cPassword);

      var credentials:String = encoder64.toString();
      headerRequests[0] = new URLRequestHeader("Authorization", "Basic " + credentials);
      req.requestHeaders = headerRequests;
  2. This solved the first issue and after running the app with valid credentials, everything worked fine. Now I needed to supress the ugly Dialog on invalid credentials.

    • You need to set the authenticate property of your request to false.

    • req.authenticate=false
  3. I need to get the status code back now and handle the exception thrown if the URL can not be loaded. This is very easy and all that's required is to add event handlers for the following events:

    • loader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS,onStatus);
      loader.addEventListener(Event.COMPLETE,onComplete);
      loader.addEventListener(IOErrorEvent.IO_ERROR,onError);

    • private function onStatus(event:HTTPStatusEvent):void {
      Alert.show(event.status.toString());
      }

      private function onComplete(event:Event):void {
      Alert.show(event.target.data);
      }

      private function onError(event:IOErrorEvent):void {
      Alert.show(event.text);
      }
    • Be aware that the event:HTTPStatusEvent is the first event handled and then the onComplete is handled.

I hope the above helps some people. Even though all I was missing was a simple property set, the Live Docs documentation was not very helpful and trying to figure out the way to accomplish the problem was difficult. I did manage to learn a heap loads of how the URLLoader, URLRequest and event handling works.

Add to your del.icio.us    DIGG This!    Technorati Cosmos Link    Post to Reddit    Add to your Furl    Add to Blinklist
Comments [9] - Leave a comment
2007-06-29 10:00:00.0

Setting IIS Maximum Connections To More Than 10

Every project I am working on, I test against 5 different browsers: Safari, Mozilla, IE7, Opera and IE6 on the same machine. Since Safari has entered the browser lineup, I have been receiving an annoying "HTTP 403.9 - Access Forbidden: Too many users are connected" message.

To solve this issue, do the following:

  1. Download the Administrative Plugin MetaEdit from Microsoft : http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B301386
  2. Install Application (Comes with old files so skip these in the installation)
  3. Go to Administrative Tool in Control Panel and launch MetaEdit 2.2
  4. Navigate to the key LM/W3WSVC/MaxConnections
  5. Change the value from 10 to the number of connections you need. I chose : 2000000000 to be extra safe ;-)

This will work on:

  • Microsoft Internet Information Server 5.1 on Windows XP Professional
  • Microsoft Internet Information Server 4.0, when used with:
    Microsoft Windows NT 4.0
    Microsoft Windows 2000 Standard Edition
  • Microsoft Internet Information Services 5.0, when used with:
    Microsoft Windows NT 4.0
    Microsoft Windows 2000 Standard Edition
Add to your del.icio.us    DIGG This!    Technorati Cosmos Link    Post to Reddit    Add to your Furl    Add to Blinklist
Comments [3] - Leave a comment
2006-07-21 11:55:00.0

GotAPI.com - Fantastic Syntax and Programming Reference

Just stumbled accross this great new site yesterday and already am beginning to refer to it as I need a function reference.

The site is : http://www.gotapi.com/

Its amazingly user friendly and as you click a topic in the center, a nice new tab appears on the top of the page allowing you to quickly jump between languages.

The loading of the functions etc is fast and the search is good! There is some great programming and thought gone into this site! I wish I thought of doing something like this.....

Tags: Tools | Useful Tips
Add to your del.icio.us    DIGG This!    Technorati Cosmos Link    Post to Reddit    Add to your Furl    Add to Blinklist
Comments [0] - Leave a comment
2006-05-16 00:17:00.0

Windows Authentication and ColdFusion

Recently a project came up where we had to integrate user login information in our database with the users Windows Authentication on the network.

Peter did a great job of implementing this using the very handy CGI variable : #cgi.auth_user#

When a person logs in using WindowsNT authentication, ColdFusion passes the users login name in the variable cgi.auth_user

Peter kept a field in the users database called usersNetworkLogin and if the users session data was 0, he looked up the database against this variable. If a user was matched, he set the user logged in with session.loggedInUserId set to the users actual id from the database.

To save a dbs lookup in the future he set a cookie on the users machine.

This is a small bit of code and logic but has helped us out enormously on the Intranet project we were working on.......

Add to your del.icio.us    DIGG This!    Technorati Cosmos Link    Post to Reddit    Add to your Furl    Add to Blinklist
Comments [3] - Leave a comment