Posts
288
Comments
25
Trackbacks
207
June 2006 Entries
Animator vs. Animation
This flash animation is both clever and funny. [via bbspot ]
posted @ Thursday, June 22, 2006 1:25 PM | Feedback (2)
Relative Images in Redirected Pages
I've just discovered a bug/issue when using redirected pages. Let's assume I have the following in a page (Animal.aspx)   <asp:Image id="i1" runat="server" ImageUrl="~/Images/foo.jpg" />
In web.config I have:   <urlMappings enabled="true">     <add url="~/Animals/Dog.aspx"        mappedUrl="~/Animal.aspx?Animal=Dog" />   </urlMappings> Run the page and the image doesn't show, because the ImageURL is incorrectly rebased.

The solution is to do the rebasing yourself; there's a whole thread on about ASP.NET Paths on Rick Strahl's Blog; there's a nice FixupUrl() method in the comments. Alternatively you can use the VirtualPathUtility: i1.ImageUrl = VirtualPathUtility.ToAbsolute("~/Images/foo.jpg");

posted @ Wednesday, June 21, 2006 12:45 PM | Feedback (2)
Windows Live Messenger Setup
I've just downloaded and installed Windows Live Messenger and have come to the conclusion that the insaller sucks. Half way through a dialog pops up indicating that I must close some programs: Outlook, and one isntance each of Word and IE (I have several open). I close them, wondering why I haven't been asked to close the other instances, and hit Retry. It does so, but then another dialog asking for more IE closures. Why can't it detect them all and ask me to close them all? Does they even need to be closed anyway? What happens if I hit Ignore? This sort of thing annoys me and scares less technical people. And while I'm complaining, do you just hate dialogs that steal the focus? You start of an installer, switch to another window and continue typing, only for the dialog to grab focus and then pop up a "Are you sure you want to cancel?" - of course I don't - I was typing in another window until you grabbed the focus and caused my typing to hit the Cancel button. IE grabs focus a lot too. Very, very annoying.
posted @ Tuesday, June 20, 2006 9:19 AM | Feedback (18)
Illustrated ASP.NET 2.0

At long last, the lasted Al and Dave book is out (my copies have just arrived). ASP.NET 2.0 Illustrated isn't just an update from the old beta books, but is around 80-90% rewrite. It does reuse some code and text from the previous books, but we decided not to just update it as we wanted to expand the samples and text and make it a more practical book for those coming to ASP.NET 2.0, either from an existing ASP.NET background, or one with no ASP.NET.

You can download the samples from my (slow) server or from some faster servers linked from the Al & Dave book page (if the links aren't their yet, just keep checking back until we get them live).

You can also run most of the samples directly from my server. Some examples are disabled for security reasons, and some aren't available as the server doesn't have enough memory to run both version of SQL Server, so any examples that use SQL Server 2005 are disabled. Also bear in mind this is a fairly slow server on a slow line, so be patient.

[Listening to: Bob Harris Saturday - - ]
posted @ Monday, June 12, 2006 12:18 PM | Feedback (1)
SQL Server Dependencies

SQL Server 2005 supports notifications, allowing it to tell you when data has changed. This is useful for many reasons, invalidating the ASP.NET cache for example. Someone asked me about this at DeveloperDeveloperDeveloper (which was most excellent as usual) and Al & I also had a query about it. The latter query was for a SiteMap provider that uses a databases, which needs to be notified when the data it depends upon changes. Since I always have to look up the steps I thought I'd blog them so it's easy to find.

  1. Cache invalidation works with both full and express editions of SQL Server 2005. The only constraint is that you must have an attached database - a user instanced express database (ie auto-attached from App_Data) will not provide notifications.
  2. The database must be at version 9 for its compatibility level. You can change this with:

    exec sp_dbcmptlevel 'Northwind', '90'
  3. You must create a broker endpoint:

    USE master
    GO
    CREATE ENDPOINT BrokerEndpoint
    STATE = STARTED
    AS TCP ( LISTENER_PORT = 4037 )
    FOR SERVICE_BROKER ( AUTHENTICATION = WINDOWS )
    GO

    ALTER DATABASE db_name SET ENABLE_BROKER;
    GO
    Replace db_name with the database name.
  4. If you are connecting to SQL as a non-admin (which you should be) then you need to grant permissions for SQL Notifications:

    -- sql_dependencey_subscriber role in SQL Server
    EXEC sp_addrole 'sql_dependency_subscriber

    -- Permissions needed for users to use the Start method
    GRANT CREATE PROCEDURE to startUser
    GRANT CREATE QUEUE to startUser
    GRANT CREATE SERVICE to startUser
    GRANT REFERENCES on CONTRACT:: [http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification] to startUser
    GRANT VIEW DEFINITION TO startUser

    -- Permissions needed for users to Execute
    GRANT SELECT to executeUser
    GRANT SUBSCRIBE QUERY NOTIFICATIONS TO executeUser
    GRANT RECEIVE ON QueryNotificationErrorsQueue TO executeUser
    GRANT REFERENCES on CONTRACT:: [http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification] to executeUser
    EXEC sp_addrolemember 'sql_dependency_subscriber', 'executeUser'
    Replace startUser with the name of the user who will start the dependency and executeUser with the user who will execute the commands requiring the dependency. This will probably both be the same user and more often than not will be the ASPNET user.
  5. Use the correct query syntax. You must use explicit column names (you cannot use SELECT *) and the table name must be qualified with its owner (eq dbo.tblMenu).
  6. You must start the dependency monitoring, probably in Application_Start in global.asax: SqlDependency.Start("your connection string here");
  7. The worst part about all of this is that it all fails silently. You'll receive an exception if you don't call the Start method, but otherwise nothing.

posted @ Monday, June 05, 2006 9:56 AM | Feedback (0)
Reader, you're a right dimwit
I've known about this practice for a long time. Those of us involved in the publishing industry understand it. Publishers want to sell books and the best way to do that is have them prominently displayed. It's called advertising and you have to pay for that. The same is true with online stores. OK there's no physical display, but the effect is the same; the publisher pays, either upfront or by offering deep discounts to the store. So remember, everything you buy, including books, is subtly advertised in some way. We're all suckers. [via Neil Gaiman]
[Listening to: Bob Harris Country - - ]
posted @ Friday, June 02, 2006 8:44 AM | Feedback (8)