May 2005 - Posts

Intro ASP.NET 2.0--Beta 2 Code Update
24 May 05 09:02 AM | despos | 7 comment(s)

As many of you pointed out lately, the source code of my book Introduction to ASP.NET 2.0 doesn't work any longer (entirely) with Beta 2. This comes as no surprise as the book was written for Beta 1. While the chapters contents remain mostly valid with some well-known omissis (DataSetDataSource, image generation service, site counters, some ADO.NET 2.0 stuff, Access-based providers), the code has been updated to Beta 2.

You can download the new sample set from here.

SQL Express Troubles
12 May 05 04:02 PM | despos | 5 comment(s)

It took me one day to install SQL Express and make full sense of it. This is mostly due to the fact that I have no idea to wipe out my machine to make room for it--I'm sure that with a clean install of Beta 2 things would have worked much better--but that's another story.

I don't know if there's a way to snoop into aspnetdb from within VS 2005. If there's one, though, either it doesn't work on my machine or I haven't been able to find it yet. I'm posting this information with the hope it helps somebody to fix things more quickly.

SCENARIO:

I have SQL Express installed with an instance name of MySqlExpress (not the default name) and an ASP.NET 2.0 application that is willing to use the personalization provider. As you know, Beta 2 dropped the Access database which was good for quick testing and demos and replaced it with aspnetdb.mdf which requires SQL Express. By default all providers use that MDF file as the storage medium and go to it through the LocalSqlServer connection string defined in machine.config. To make it accept a non-default name for the product instance I had to tweak machine.config to replace the default name (SQLEXPRESS) with my own. (A less intrusive approach entails using the app's web.config file, but I'm writing code for my next Programming ASP.NET 2.0 book(s) so a modified web.config would have forced readers to tweak code before running.) Now that everything works well and data is correctly read and saved to the MDF file, another problem shows up.

PROBLEM:

How can I snoop into the contents of aspnetdb.mdf? It was easy with Access or SQL Server databases in Beta 1. It would probably as much easy in Beta 2 if I could rely on a clean and perfect installation. I see that MS released SQL Express Manager, a lightweight tool for SQL Express that resembles Query Analyzer. Any way I can attach my MDF file to that tool?

SOLUTION:

When I have a database problem I usually take some time to bother my friend Fernando Guerrero (Solid Quality Learning). He brought me to see the light. The idea is attaching the MDF file of choice to SQL Express Manager and then go through the interface of the tool.

CREATE DATABASE ASPNetDb
ON (FILENAME = 'C:\Inetpub\wwwroot\ProAspNet20\App_Data\aspnetdb.mdf')
FOR ATTACH;

Now the application specific aspnetdb.mdf file is visible through SQL Express Manager (after a refresh).

TIPS:

  • If you want to snoop into the profile data, run SELECT * FROM aspnet_profile
  • If you want to make sure that the one displayed is the right database (who knows with file names), use sp_helpdb aspnetdb

I am happy now. But I would like to know if there was a simpler way out.
  

IsCrossPagePostBack
12 May 05 10:27 AM | despos | 11 comment(s)

I know it's just my fault but for a while I've been thinking that IsCrossPagePostBack was supposed to return true if the current page was called through a cross-page posting. So I was led to writing code like this:

// This code lives in TARGET.ASPX--the target of a posting
protected void Page_Load(object sender, EventArgs e)
{
   if (!IsCrossPagePostBack)
   {
      Response.Write("Sorry, you can only invoke me through cross-page posting.");
      Response.End();
      return;
  
}
   // other code here
}

This code never worked as expected, in Beta 1 as well as in Beta 2. Recently, I realized it was my fault as IsCrossPagePostBack is designed to return true for the PreviousPage page object, not for the current page. In other words, it returns true for the page which STARTED a cross-page posting, not for the page being invoked that way. The code above should be rewritten as follows.

// This code lives in TARGET.ASPX--the target of a posting
protected void Page_Load(object sender, EventArgs e)
{
   if (PreviousPage != null && PagePrevious.IsCrossPagePostBack)
   {
      Response.Write("Sorry, you can only invoke me through cross-page posting.");
      Response.End();
      return;
  
}
   // other code here
}

It works but to me this code raises some questions. Why checking both? Does it really exist a scenario with a non-null PreviousPage and IsCrossPagePostBack set to false? YES.

In ASP.NET 2.0, Server.Transfer integrates with this mechanism and enjoys a non-null PreviousPage too for you to comfortably access any controls in the caller. In this case, though, IsCrossPagePostBack is false.

In summary, checking PreviousPage against null is sufficient if you don't need further details--was it called through cross-page posting or Server.Transfer.

Great information here.

 

The Dev tool of my dreams
12 May 05 10:07 AM | despos | 6 comment(s)

Nikhil on the ASP.NET team released a dev helper tool that I first dreamt of when I was a newbie to ASP.NET. Yeah, sometimes I really wonder if there was ever a time when people were used to write code without .NET <g>

The tool is built as a combination of a server and client component. The server component is a HTTP module you have to install and make available to all apps or just the one you want to play with. The client component is a Browser Helper Object for IE only.

Several times lately I was near enough to writing that tool myself. What stopped me was the difficulty of writing a BHO w/o .NET. A BHO must be a COM object written according to the guidelines you find here. I never considered switch back to ATL and I don't like much writing COM objects through .NET. That's why I heartily welcome the tool from Nikhil.

Join me sending a monumental THANK YOU to Nikhil and the ASP.NET team!

More Posts