Powered by discountASP.NET
referal ID: sdtref
Why recommend discountASP.NET?
$720 in referrals so far!

About/Contact

Steve Trefethen

Steve Trefethen is a Software Architect and Director of Software Training at Falafel Software in Capitola, CA. You can reach Steve here.

All opinions you read here are Steve's own and are not necessarily those of Falafel Software.

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

Disclaimer

The posts on this weblog are provided AS IS with no warranties, and confer no rights. The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
If you're new here, you may want to subscribe to my RSS feed, follow me on Twitter, or subscribe via email. Thanks for visiting!

Invalid Parameter Error using Facebook Developer Toolkit 1.6

May 29 2008 6:49AM

[UPDATE: June 3, 2008] Problem solved.
I’ve been playing with a Facebook Application started using my Facebook Developer’s Toolkit Starter Kit (for v1.6) and I’m seeing an "Invalid Parameter" error which occurs if the application is left idle in the browser then an attempt is made to interact with the app and the session times out. The error is as follows:

Server Error in '/FacebookASPNET' Application.

Invalid parameter

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Facebook.Exceptions.FacebookException: Invalid parameter

Source Error:

Line 32:   else if (!String.IsNullOrEmpty(authToken))
Line 33:   {
Line 34:       _fbService.CreateSession(authToken);
Line 35:       Session["facebook_session_key"] = _fbService.SessionKey;
Line 36:       Session["facebook_userId"] = _fbService.UserId;

Source File: e:\web\nnn\htdocs\FacebookASPNET\Default.aspx.cs    Line: 34

Stack Trace:

[FacebookException: Invalid parameter]
   Facebook.API.FacebookAPI.ErrorCheck(XmlDocument doc) +900
   Facebook.API.FacebookAPI.LoadXMLDocument(String rawXML) +127
   Facebook.API.FacebookAPI.CreateSession() +92
   Facebook.Components.FacebookService.CreateSession(...) +37
   _Default.Page_Load(...) in Default.aspx.cs:34
   System.Web.Util.CalliHelper.EventArgFunctionCaller(...) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(...) +33
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(...) +1436


Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433

The problem is discussed on the Facebook Developer’s Wiki here with the solution being to add the following code to allow for an IE issue regarding pages loaded in a frame from a different domain:

protected override void OnPreRender(EventArgs e) { Response.AppendHeader("P3P", "CP=\"CAO PSA OUR\""); base.OnPreRender(e); }

I’ve gone ahead and added this to my application but I’m still seeing this error. There are a number of discussions on the CodePlex project pages for the Toolkit related to this error message but AFAICT, it doesn’t appear this has been resolved at least not for IFRAME applications. In fact, the last message in this thread on the subject a user mentions switching to Facebook.NET which apparently doesn’t exhibit the same behavior. I haven’t had a chance to debug this further as I’m swamped with other work right now however, I thought it might be worth posting about to start gathering information about it. I’ll probably throw together a quick test using Facebook.NET for comparison and see what happens.

Anyway, have you run into this problem? Did the OnPreRender solution work? I’d like to update the starter kit as necessary to resolve this issue so if you have any details please let me know. Thanks!

FacebookDel.icio.usDigg It!

Tags: ,

URL rewriting in ASP.NET and web.config settings

April 21 2008 4:27PM

The other day I blogged about potentially switching to blogengine.net but one of the major issues is ensuring the URL’s I have in dasBlog either continue to work or redirect accordingly. To that end, I started investigating URL rewriters for ASP.NET and found this post of ScottGu’s very helpful. He mentioned two different Open Source rewriters and I opted for UrlRewriter.net which describes itself as:

UrlRewriter.NET is an open-source, light-weight, highly configurable URL rewriting component for ASP.NET 1.1 and 2.0. UrlRewriter.NET provides similar IIS Rewrite capabilities that the Apache web server provides with mod_rewrite and .htaccess. You don’t need to install an ISAPI Rewrite filter to use the component. Best of all, UrlRewriter.NET is free and licensed with a very permissive MIT-style licence.

I found it to be all of the above and the install/configuration to be very straightforward not to mention it has good online help and a support forum.

One caveat that I ran into though was that once installed at the root I started seeing this error in my other ASP.NET applications:

Server Error in '/blog' Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Could not load file or assembly 'Intelligencia.UrlRewriter' or one of its dependencies. The system cannot find the file specified. (E:\web\xxxxxxx\htdocs\web.config line 11)

Source Error:

Line 9:    <system.web>
Line 10:     <httpModules>
Line 11:       <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, 
Intelligencia.UrlRewriter" />
Line 12: </httpModules> Line 13: </system.web>

Source File: E:\web\xxxxxxxx\htdocs\web.config    Line: 11


Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433

The Fix

To fix this I added the following to the web.config files of my other ASP.NET applications removing the new assembly dependency:

1 <system.web> 2 <httpModules> 3 <remove name="UrlRewriter" /> 4 </httpModules> 5 </system.web>

If you’re aware of other options that don’t require changes to every web.config I’d love to hear about them. At any rate, while I haven’t decided to switch blog engines yet I now have the pieces in place to do just that.

What do you use for URL rewriting particularly in a hosted environment?
FacebookDel.icio.usDigg It!

Tags: , ,

Facebook Starter Kits for VS.NET updated

January 15 2008 7:41AM
Since I’ve had a lot of interest in the VS.NET Starter Kits I created for the Facebook development I thought it worth mentioning I’ve updated both to their latest releases.

Facebook Developer ToolKit is now at v1.5 (starter kit download)

Facebook.NET is now at v0.3 (starter kit download)

Here are the relevant blog posts:

Visual Studio Starter Kit for Facebook application development

VS.NET starter kit for Nikhil Kothari’s Facebook.NET

Enjoy!
FacebookDel.icio.usDigg It!

Tags: , , .NET | Programming

Microsoft's ASP.NET MVC framework will be great for Automated UI testing

December 31 2007 6:12AM

I’ve written automated UI tests using Selenuim running against a large ASP.NET Web 2.0 ERP application with great success. However, IMO the single biggest productivity killer for writing such tests is ASP.NET WebForms ID name mangling where ID’s are changed from something like "lblSysMText" at design time to "ctl00_cphContents_dlMessages_ctl01_lblSysMText" at runtime. Fortunately, Selenuim supports the use of XPATH expressions so searching for the above tag can be done using the following:

//span[contains(@id, "lblSysMText")]

Name mangling is a huge problem and thwarts all sorts of automated test tools whether you’re using AutomatedQA's TestComplete or a something like Selenuim. Whenever you have a situation where a simple containership change like moving a control into a DIV can break an automated test you’ve got a problem. These sorts of changes occur all the time on WebForms which are actively being developed meaning unless your tests are written using a partial match logic, like what I’ve illustrated above, you’ll be faced with lots of bogus failures which not only kill productivity but undermine your test automation efforts as the tests will be viewed as fragile and a waste of time.

MVC to the Rescue

Scott Guthrie wrote:

This model view controller (MVC) framework for ASP.NET provides a structured model that enables a clear separation of concerns within web applications, and makes it easier to unit test your code and support a TDD workflow. It also helps provide more control over the URLs you publish in your applications, and more control over the HTML that is emitted from them.

With the MVC framework name mangling will be a thing of the past. I believe not only will the MVC framework make unit testing easier it will be a major win for automated UI testing for ASP.NET apps. You’ll no longer have to jump through hoops to figure out the ID of a given tag on the page.

Last but not least, with MVC style development you’ll finally be able to use ID’s like #lblSysMText in your CSS again.

FacebookDel.icio.usDigg It!

Tags: , ,

Microsoft's MVC framework means you'll need to rethink your WebForm world

December 20 2007 8:10PM
With the advent of Microsoft’s new MVC framework for ASP.NET I think there will be a fairly significant impact on developers who have come to rely heavily on WebForms and related controls. I believe the new framework will require a significant "rethink" of how applications and controls are developed. If you watch Scott Hanselman’s video you’ll see he uses Rob Conery’s Mvc.ToolKit to flesh out the UI and notice that it doesn’t use the designer nor web controls at all.

The MVC framework is clearly going to change how the VS.NET web form designer will be used and certainly makes it less important. It will be interesting to follow the evolution of the framework and to see how MS updates the designer and code editor to fit this new (as in new to MS) model. It will also be interesting to see how 3rd party control companies like Telerik and Developer Express respond.

While at CodeGear I had frequent discussions with Jim Tierney (who I co-developed Delphi’s ASP.NET designer with) about moving Delphi’s designer away from being a WebForm centric because of the development costs involved and instead focus more on the code editing experience. I think the MVC style of development does just that and I expect Microsoft to come up with a number of improvements to the framework and tooling to better support it. I’ll be curious to watch what this means for Delphi’s ASP.NET support.

One thing I think is particularly interesting is with WebForms out of the way ASP.NET developers will be in a better position to leverage non-Microsoft AJAX frameworks such as Dojo, Prototype etc. etc.

Kudos to Microsoft for following through on this much needed alternative to WebForms!
FacebookDel.icio.usDigg It!

Tags: ,

Facebook Developer Toolkit v1.3 Starter Kit updated

November 16 2007 7:01AM
UPDATED Nov. 6, 2008: A new release is available here.

I’ve updated my Facebook Starter Kit to version 1.3 of the Facebook Developer Toolkit published by Microsoft available on CodePlex. I also cleaned up the code and moved the Appkey and Secret so their read from web.config.

Btw, I’ve had a few questions in email about how to fetch a friend list which can be done as follows:

if (!IsPostBack)
{
System.Collections.ObjectModel.Collection
<User> userinfo = _fbService.GetUserInfo(_fbService.UserId); Label1.Text = "Hi, " + userinfo[0].FirstName;
Image1.ImageUrl
= userinfo[0].PictureUrl.ToString();

// Use the FacebookService Component to populate Friends System.Collections.ObjectModel.Collection<User> Friends =
_fbService.GetFriends();
for (int i = 0; i < Friends.Count; i++)
DropDownList1.Items.Add(Friends[i].FirstName.ToString());
}

If you haven’t seen it I’ve also created a starter kit for Nikil Kothari's Facebook.NET framework so be sure to take a look a that as well.

Enjoy!

FacebookDel.icio.usDigg It!

Tags: , .NET | Facebook | Programming

Automated testing of ASP.NET web applications using Selenium

July 31 2007 8:06AM

Lately, I've been focused on Web Application testing frameworks and I've been looking at a number of different options and having varying degrees of success. That is, of course, until I started looking at Selenium after Lino mentioned it to me and I'm very impressed. Selenium is an open source project with multiple tools designed for testing web applications. Selenium includes:

  • Selenium IDE an add-on to Firefox use for recording test scripts
  • Selenium RC (Remote Control) a Java server used for execution of test scripts
  • Selenium Core client side testing support for web applications added directly to your application
All of these are interesting in their own right so be sure to look closely at each piece.

Selenium IDE

Selenium IDE
The Selenium IDE is a non-modal dialog add-on for Firefox that supports Selenium test development. In fact, it's more than fair to call this single dialog an IDE because it fully supports recording, development and debugging of test scripts. Additionally, it can format test scripts in any of the following for use with Selenium RC:
  • HTML
  • Java
  • C#
  • Perl
  • PHP
  • Python
  • Ruby

A Selenium test script consists of a series of Commands which have a Target and optionally a Value. For example, browsing to a web page using Selenium consists of the following:

Command: open
Target: http://localhost/myapp

To click on a link titled "About" on a page the Command might look like this:

Command: clickAndWait
Target: link=About

This will initiate the click and wait until the new page is done loading. There are literally hundreds of commands to choose from covering input (both keyboard and mouse), control manipulation, drag/drop, evaluation, verification, waiting, browser manipulation and just about anything else you'll need.

If you've done any UI testing at all you're familiar with the challenge of manipulating a UI programmatically in a manner independent from of the size, position or location of the control you're trying to manipulate. Selenium solves this problem using XPATH and providing the ability to locate controls based on XPATH expressions alleviating the need to hard code HTML tag structure into a test script. This is particularly crucial for ASP.NET testing since the runtime mangles the ID attributes of rendered tags. For example, the ASP.NET runtime may render ID attributes that look like:

id="ctl00_cphContents_gridMaint_DataGrid"

Finding this control using an XPATH expression can be simplified to something like this:

//table[contains(@id, "gridMaint")]

In the event the nesting of the DataGrid changes the script will continue to function properly as long as table's ID contains the text "gridMaint".

Example of using the Find button on the Selenium IDE

Notice the link is highlighted in the browser

Playing back tests using Selenium TestRunner

The Selenium IDE has a toolbar button that will launch a feature called TestRunner which allows you to playback your tests using controls hosted in an IFRAME inside your browser. Here's what it looks like:

Selenium TestRunner

You can playback your entire test from right within your browser. It's like having the IDE built right into your application.

Selenium RC

Next, is Selenium RC which is a Java server application used execute Selenium tests and drive a browser instance through AJAX communication with the browser. To start Selenium RC simply execute the following from a command prompt:

java -jar selenium-server.jar -interactive

Since I'm focused on .NET I'll discuss the C# approach. Once you've recorded and debugged your test you can capture it as C# and compile it into an NUnit compatible assembly where upon execution it will drive Selenium RC to manipulate the web application through a browser instance running on your desktop. Here is an example of the above recorded test in C#:

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;

namespace SeleniumTests
{
    [TestFixture]
    public class NewTest
    {
        private ISelenium selenium;
        private StringBuilder verificationErrors;
        
        [SetUp]
        public void SetupTest()
        {
            selenium = new DefaultSelenium("localhost", 4444, "*firefox",
                              "http://localhost:4444");
            selenium.Start();
            verificationErrors = new StringBuilder();
        }
        
        [TearDown]
        public void TeardownTest()
        {
            try
            {
                selenium.Stop();
            }
            catch (Exception)
            {
                // Ignore errors if unable to close the browser
            }
            Assert.AreEqual("", verificationErrors.ToString());
        }
        
        [Test]
        public void TheNewTest()
        {
            selenium.Open("/selenium-ide/");
            selenium.Click("link=About");
            selenium.WaitForPageToLoad("30000");
        }
    }
}

Generation of NUnit compatible tests is great because it makes it really easy to incorporate Selenium test suites into a continuous integration environment like CruiseControl.NET.

Conclusion

If you're in need of a web application testing framework you owe it to yourself to check out Selenium. I'd go so far as to say if you're doing doing any web related development and you're not already using Selenium you should stop right now and go download it. Here are there RSS feeds.

After playing with Selenium for about an hour I was easily able to:

  • Record tests against a RIA
  • Build a C# NUnit compatible assembly to drive Selenium RC
  • Integrate the tests into an automated build using CruiseControl.NET

Since then I've been able to really dig in and accomplish a lot of work in a very short period of time. The next step is to build up a nice battery of tests and dig into NCover to help figure out where the holes are.

Lastly, I just want to tip my hat to the ThoughtWorks and volunteers and supporters of the Selenium project. Kudos for such a great framework!

FacebookDel.icio.usDigg It!

Tags: , , , , , , , , ,