August 2005 - Posts

There is no little out there on this new concept, but luckily the latest MSDN magazine had an article on this.  The power of the asynchronous page is that it allows you to release the thread that is executing your page request during long operations (i.e.: web service calls).  Once the call is complete, it will go out and grab a new thread from the pool and finish the requet.  This will allow for a large performance increase in our application since threads aren't blocking waiting for a rate shop to come back.
Any how, there are numerous examples on how to use the async methods built into the web service proxy to make this work.  The real question is how do we create our own async methods since our web service calls are inside of a wrapper class.
I've got a copy of the MSDN Magazine sitting on the shelf if you are interested in reading it or you can probably find it online somewhere.  This is definitely something we will want to implement in our Reservations project.
I found this article very relevant to what we are doing today.  We already knew that ASP.NET 2.0 added support for XHTML and whatnot, but this article highlights some of the features in Visual Studio 2005.
The way we share control libaries today is kind of rigged.  We basically make a project reference and then set up a virtual directory to the path of the ascx files.  It is a little bit better in Visual Studio 2005.  This article walks you through how to do it.
How many times have you written a page or control to authenticate a user? You know you have to put a couple of textboxes in for username and password, a submit button, maybe a call to a sql server or wherever to authenticate the user. ASP.NET 2.0 has a ton of new control to simply user authentication. The cool thing is that it has controls to handle login, logout, displaying different content to authenticated users (or users in different roles), and even controls to create new users.
As I have said before ASP.NET 2.0 is provider based. This means that the implementation of Profile, Personalization, and Membership is not coded into the controls but into a provider. You can then build your own custom providers to do whatever you want.
ASP.NET has some built in membership providers out of the box. This is typically configured in the web.config and would look something like this.
<membership defaultProvider="QuickStartMembershipSqlProvider" 
    <providers> <add name="QuickStartMembershipSqlProvider" 
    type="System.Web.Security.SqlMembershipProvider, System.Web, 
Version=, Culture=neutral, 
Once you have a provider set up, creating a login page is as simple as dropping a login control onto a page.
<asp:Login id="LoginControl" runat="server" DestinationPageUrl="/index.aspx" />
That is all that is required to authenticate a user. The control supportsseveral parameters to specify styles, etc. In the future, I will talk about some of the additional controls available to handle login as well.
There are some ASP.NET 2.0 courses that are available online for free for a limited time.  These self-paced course provide a good way to pick up on some of the new features in ASP.NET 2.0.  If you happen to try any of them, please let me know.
As you may have heard now, there is a series of configuration web pages that can be used to configure various settings in your ASP.NET application.  Under the Website menu in Visual Studio 2005, there is a menuitem called ASP.NET Configuration.  Clicking this will launch a personal web server on a random port which will allow you to configure your application.
This is a great alternative to hand editing the web.config.  From here you can add or edit appSettings keys, configure debugging, smtp, set up security and configure providers.
For this to work on a server a website will have to be configure somewhere on any web instance.  The configuration site exists in the files ASP.NETWebAdminFiles in the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215 folder.  This application would have to be set up on the server that you wanted to run it on.  You then just pass it the physical path to the web application in the applicationPhyiscalPath querystring value and the relative url to the application in the applicationUrl querystring value.  For example:
That link obviously won't work unless I happen to have Visual Studio running with the personal web server still running as well on that port.
Unfortunately, the caveat to all of this is that the authenticated user must have write access to the web.config on the web server (not a likely scenario in production).
I finally installed SQL Server 2005 on my local machine.  It is kind of a pain to install if you have had Sql Server Express Beta 2 installed.  Anyhow, it appears to be up and working, so if you want to connect to it and mess with it at 5w-42109 feel free.  I also have the SQL Server 2005 installation disc handy if you want to install the client tools including SQL Server Management Studio.
They have really screwed with the way Base Pages and Base Controls work (and not necessarily for the better).  The new migration wizard will detect your base pages and controls and attempt to move them to the new ASP.NET 2.0 way of doing things.  The @Page and @Control compiler directives now support an attribute called CodeFileBaseClass.  During mirgation, the wizard automatically converts any page or control that does not inherit from Page, Control, WebControl, UserControl, HtmlControl, or HtmlGenericControl.  It's definitely a different way of doing things and I am not sure if I necessarily like it.
Scott Guthrie posted an article on all of the changes to the web project system in Visual Studio 2005.  Web projects are completely different now and it is important to read this article to know exactly what the changes are.
In Beta 2, the default rendering was XHTML 1.1 strict. Since some people depended on the name attribute being on the form tag (not sure who), they decided to make the default Transitional. Luckily, this is easy to override.
Just add the following tag to the system.web section in your config file.
<!--Possible modes are "transitional", "strict", and "legacy".
<xhtmlConformance mode="strict" />
The builds keep coming and a release candidate is not far away.  The August 2005 CTP was just released for Visual Web Developer Express.  As usual, install on VM or a machine you don't care about.
Well I found another class for playing sounds yesterday.  The SoundPlayer class in the System.Media namespace can be used to play sounds asyncronously and syncronously.  Playing the sound is simple, simply initialize the class with the filename in the constructor or you can use the Load method if the class is already instantiated.  Then simply call the Play method. 
Here is an example.
// load the sound
SoundPlayer soundPlayer = new SoundPlayer(soundPath);

// play the sound
I have spent a lot of time talking about all sorts of new features in .NET 2.0, but I have never really spent any time talking about the basics of how the page itself has changed.  I always assumed it was kind of obvious, but it really isn't if no one has told you.
The first thing you need to know about is the concept of the partial class.  I may have talked about this at some point.  Basically, it allows multiple files to come together to create one class when compiled. 
Second, you need to now understand that your markup that you put in your .aspx or .ascx is truly code.  It can be compiled as such.  When you drop any of these new controls onto a page in the designer, that control is declared.  It does not (and cannot) have a line in the code behind file declaring it (i.e.: System.Web.UI.WebControls.TextBox PickupLocationTextBox).  This means there is no more going into the designer of your markup and trying to get it to autogenerate those declarations in the code behind for you.
Out of the box, here is what the markup of a page looks like when you create it.
<%@ Page Language="C#" AutoEventWireup="true" 
CodeFile="Blah.aspx.cs" Inherits="Blah" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title> </head> <body>     <form id="form1" runat="server">     <div>     </div>     </form> </body></html>
Notice it automatically sets the doctype to a flavor of xhtml.  The codebehind is even simpler.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Blah : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
Notice that there are not any hidden regions containing OnInit and event bindings.  All events on controls are declared in the markup now, not by adding a line in the OnInit method.
Those of you who have already worked with it a bit probably already understand this, but if you haven't worked with ASP.NET 2.0 at all yet, this information will prove useful.
There are going to be numerous way to compile ASP.NET applications in Visual Studio 2005.  Dynamic compilation will allow you to just drop a .cs file onto the server and have it compile and run on the fly.  When you use the Publish Web Site feature, you will have the ability to compile entire directories into single DLLs or even a single control or page.  This will allow us to patch a particular control without affecting the rest of the application.
Supposedly ASP.NET v1.1 compilation is still around in there somewhere but I have yet to see it.
I was certainly one of the people complaining about the fact that they removed the ability to exclude a file from a web project.  Scott Guthrie posted this weekend that this is one of the features that has been added back.  We should see it in the future RC1 build.
More Posts Next page »