SpriteHand
Module Border
  Why is my Default.aspx page Always Executed?
Module Border
Location: BlogsAndy's Blog    
Posted by: host 7/7/2008 3:53 PM

This is a new Silverlight spin on an old problem. Let's say you have a Default.aspx page with some code behind logic in it. One day you notice using the debugger that the code-behind logic in Default.aspx.cs is always executed - even when accessing a different aspx page.

This problem can arise for a couple of common reasons. One reason is that someone copied the Default.aspx page to a new page and forgot to change the Codebehind and Inherits page directives to a new code-behind class. You can usually solve this by searching other pages for references to _Default in their page header:

<%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false"
Inherits="VersaTrans.GPS.Web.UI._Default" %>

Another more common reason though, is that you have dynamically assigned a Url for a resource, such as an img src, and the src attribute evaluates to an empty string:

<IMG src='<%# Eval("ImageUrl") %>'>

... if bound to an empty field, would evaluate to:

<IMG src="">

When this happens, the Request will go to the root of your website, which in turn will execute the default page of your site - normally Default.aspx. You can use a tool such as Fiddler or Web Development Helper to help troubleshoot this issue. By capturing the http traffic, you will see a request for the root of your site.

A Silverlight Twist
The problem described above is hard enough to track down in an ASP.NET environment. But to make it even more confusing, a Silverlight application within the ASP.NET website can also cause the problem.

A common way to dynamically assign an image source in Silverlight is shown below. We create an ImageSource based on Uri and the set the SourceProperty of the Image to the Uri:

Uri imageUri = new Uri(imageUrl, UriKind.Absolute);
ImageSource imgSource = new System.Windows.Media.Imaging.BitmapImage(imageUri);
img.SetValue(Image.SourceProperty, imgSource);

... but if the variable imageUrl above is an empty string, we are back to the same issue described above for the ASP.NET environment. The browser will request the root of the web site, and the default page will be executed.

To avoid this problem, check for empty Image Source's when assigning Url's to image objects.

Permalink |  Trackback

Comments (1)   Add Comment
Re: Why is my Default.aspx page Always Executed?    By Anonymous on 7/9/2008 2:17 AM
Great tip!


Title:
Comment:
Add Comment   Cancel 
Module Border Module Border
Module Border
  Blog_List
Module Border
Module Border Module Border
Module Border
  Subscribe
Module Border

RSS

Module Border Module Border
Module Border
  Diversions
Module Border

DESTROY ALL INVADERS
A scrolling shooter game where the objective is to destroy the invading UFO's flying over a neighborhood of your choosing. Imagery provided by Microsoft Virtual Earth. Created using Silverlight 2.
PLAY IT

INFO AND CODE



HOOK SHOT
This little basketball game was submitted as an entry to the TeamZoneSports Silverlight Contest. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

INFO AND CODE



SORT THE FOOBARS
A game where you need to sort the good foobars from the bad ones. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



POLYGON PHYSICS DEMO
A demo showing polygon physics where the user draws physics objects with the mouse. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



SILVERLIGHT ROCKS!
Destroy the asteroids before they destroy your ship! Created using Silverlight 2.
PLAY IT

INFO AND CODE



FISH GAME
A simple game of harpoon-the-fish. Written using the AJAX Sprite Toolkit.
PLAY IT

INFO AND CODE

Module Border Module Border
Module Border
  Search_Blog
Module Border
Module Border Module Border
Module Border
  Blog_Archive
Module Border
Module Border Module Border
Copyright (c) 2008 andy.beaulieu.com - Login