Wednesday, March 05, 2008

It's MIX and that always means great stuff coming to web developers. This year it's the ASP.NET MVC Preview 2 and Silverlight 2. Great times are ahead of us.

Grz, Kris.

Wednesday, March 05, 2008 8:31:17 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Friday, February 08, 2008

Just launched on the ASP.NET website: the ASP.NET wiki. Take a look at it and see if you can contribute. Also take a look at the publishing guidelines.

Grz, Kris.

Friday, February 08, 2008 9:54:21 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Thursday, February 07, 2008
Just read that Scott Mitchel has started another series on ASP.NET articles. This time he'll be covering security in ASP.NET. Be sure to check it out: Security tutorials.

Grz, Kris.
Thursday, February 07, 2008 9:47:35 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, November 19, 2007

on

Lots to learn, not enough free time unfortunately.

Grz, Kris.

Monday, November 19, 2007 8:18:22 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Sunday, September 09, 2007

Standard out of the box ASP.NET 2.0 uses SQL Server Express for the Application Services (Membership, Roles, ...). However sometimes you don't want it to be like that because you don't want to pay extra for SQL Server to your hosting company. In the past you practically had to rewrite your application or at least the Data Access Layer to be able to use an alternative database. Thanks to the Provider model that's being used by ASP.NET 2.0 it's possible to develop an application while another team could create an alternative provider and afterwards use some configuration to let your application make use of this new provider.

So, when you're reading this, it means you're interested in changing your default SQL Server based applications services to Access. First of all make sure that you download the Sample Access Providers provided by Microsoft.
This is a .vsi file and you could run it to get installed. But rather then doing that, you simply rename the extension from vsi to zip. That's right, you simply rename it and use a zip utitlity, like the built in zip functionality of Windows to extract the files.

accessproviders01 
Figure 1: the unpacked Sample Access Providers

These are the files I got after extracting the .zip file. You see there's already a full blown ASPNetDB.mdb file in it that has the needed tables and queries to be able to support  the Application Services. Figure 2 shows what's already available. As you can see

accessproviders03
Figure 2: Overview of the available tables and queries in the accompanied Access database file.

After extracting the files we still need to compile the source code in order to be able to integrate the providers into our web application. If you have Visual Studio or Visual C# Express installed you open your IDE of choice. You navigate to the menu and click File, Open, Project/Solution. Once the dialog opens you navigate to where you extracted the contents of the zip file. Select the Access.csproj, see Figure 1, and click the Open button.

Once opened you can see the following in the solution (Figure 3). Now you just have to build the solution, preferably in Release mode.

accessproviders04
Figure 3: solution

Ok, the output of building the solution provides us with an assembly named SampleAccessProviders.dll. To find it back you just need to open a windows explorer and navigate to the place where you extracted the zip file to. There you should see a newly created subfolder called bin and in that one that's called Release. In the Release folder you'll find the built assembly.

Now that we have created the assembly it's time to actually use it. Open your Visual Studio or Visual Web Developer Express and create a new website. In the project you create a new subfolder called bin. After creation right click on it and choose Add existing item... from the context menu that appears. Navigate to the place where the built assembly is. Add it to the bin folder of the website project. After that repeat the same thing with the access database (ASPNetDB.mdb) file but this time put it in the dedicated folder App_Data which is one of the predefined ASP.NET 2.0 subfolders.

Open the web.config file of the website project. You'll need to make some adjustments here in order to be able to use it Access provider. When you take a look at figure 1 you'll see that the extracted zip file also contains a web.config. It already contains the needed parts so the only thing required is just to copy paste the needed configuration parts.
First of all the connectionstring to the access database:

    <connectionStrings>
        <add name="AccessFileName" connectionString="~/App_Data/ASPNetDB.mdb" providerName="System.Data.OleDb"/>
    </connectionStrings>

 Also be sure to change the authentication mode which defaults to Windows. Make it use Forms instead like this:

<authentication mode="Forms">
  <forms loginUrl="mylogin.aspx" defaultUrl="Login.aspx"/>
</authentication>

After that you can simply copy in the providers that you need. In this tutorial I'll only copy in the Membership provider part:

<membership defaultProvider="AccessMembershipProvider">
    <providers>
        <clear/>
        <add name="AccessMembershipProvider" 
                type="Samples.AccessProviders.AccessMembershipProvider, SampleAccessProviders" 
            connectionStringName="AccessFileName" 
            enablePasswordRetrieval="false" 
            enablePasswordReset="false" 
            requiresUniqueEmail="false" 
            requiresQuestionAndAnswer="false" 
            minRequiredPasswordLength="1" 
            minRequiredNonalphanumericCharacters="0" 
            applicationName="SampleSite" 
            hashAlgorithmType="SHA1" 
            passwordFormat="Hashed"/>
    </providers>
</membership>

Other provider parts, like the Roles and Profile, are just as easily copied.

Just to see if things are working is quite easy. Just open the ASP.NET Configuration Tool. You do that by navigating to the menu and click Website, ASP.NET Configuration. A browser opens with the tool in place. Click the fourth tab (Provider). Select the second link ("Select a different provider for each feature (advanced)). There you'll see that the access provider is selected (figure 4)

accessproviders05
Figure 4: Provider tab in the ASP.NET Configuration Tool

In the membership configuration you notice the <clear/> tag. This clears all previous settings from a hierarchical higher configuration. If you remove that particlar line you'll see that you get another radiobutton option that lists the default AspNetSqlMembershipProvider. If you would select that option SQL Server's used again. 

Grz, Kris.

Sunday, September 09, 2007 8:25:12 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [1]  |  Trackback
 Friday, July 27, 2007

A site that I visit frequently just got a repaint job. It looks nice I must say. Be sure to check it out at http://www.asp.net/. If you should have any suggestions or remarks you can leave them in the Feedback forum.

Grz, Kris.

 |  | 
Friday, July 27, 2007 8:22:49 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Friday, June 15, 2007

Hi,

just found out about this sample application: .NET StockTrader Sample Application.

This application is an end-to-end sample application for .NET Enterprise Application Server technologies. It is a service-oriented application based on Windows Communication Foundation (.NET 3.0) and ASP.NET, and illustrates many of the .NET enterprise development technologies for building highly scalable, rich "enterprise-connected" applications. It is designed as a benchmark kit to illustrate alternative technologies within .NET and their relative performance. The application offers full interoperability with J2EE and IBM WebSphere's Trade 6.1 sample application. As such, the application offers an excellent opportunity for developers to learn about .NET and building interoperable, service-oriented applications.

Since the weather in Belgium isn't that great at the moment I think I know what I'll be checking out the next week.

Grz, Kris.

Friday, June 15, 2007 6:22:59 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Saturday, June 09, 2007

I see that question appearing on the ASP.NET forums over and over again so I decided to dedicate a post on the subject. There are, depending on the .NET framework properties available that can help one out:

Grz, Kris.

Saturday, June 09, 2007 6:02:12 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, May 28, 2007

Normally you have the possibility to choose Enable Selection in the Smart tag of a GridView control. This results in an extra column in front of the GridView with the text Select. But what if you don't want it like that but want to be able to use an image for example to select that row?

Well, a neat solution's to add a TemplateField and in the ItemTemplate place an ImageButton control. Why this one? Because it has a CommandName property available you can use. All you have to do is to set it to the predefined word Select.

Here's a small example to show what I mean:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"> <Columns> <asp:CommandField ShowSelectButton="True" /> <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" /> <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" /> <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" /> <asp:TemplateField> <ItemTemplate> <asp:ImageButton ID="ImageButton1" CommandName="Select" runat="server"
ImageUrl="../App_Themes/Black/Images/bullet-1.gif" /> </ItemTemplate> </asp:TemplateField> </Columns> <SelectedRowStyle BackColor="Red" /> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [LastName], [FirstName], [Title] FROM [Employees]"></asp:SqlDataSource> </div> </form> </body> </html>

Grz, Kris.

Monday, May 28, 2007 2:46:12 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Sunday, May 27, 2007

When you start creating a new ASP.NET 2.0 site with Visual Studio 2005 or Visual Web Developer Express (VWD) and want to start using it you'll notice that a new file in the App_Data folder gets created besides your own database, namely the aspnetdb.mdf file. This extra database holds all the tables and stored procedures to let Membership, Roles, Profile etc run smoothly.

However a problem arises when you don't want to use that dedicated new database when you want to deploy to your live webserver, certainly not when you use a host that only offers one database and charges you extra for another database. Luckely you can control things more when using the dedicated aspnet_regsql tool that ships with the .NET 2.0 framework.

What I'm about to describe in this article is how to use that tool to generate a SQL script that you can use to run on your other database with a tool like SQL Server Management Studio (SSMS). In this example I'll be using the installed Northwind database on my localhost developer machine.

Just start up a new DOS box by going to Start | Run and type in cmd followed by enter. In Windows Vista you push the blue windows logo button and in the field with the text Start Search you type in cmd followed by ctrl + shift + enter. The reason for that combination is that you must run it under Admin privileges or else the to be generated file doesn't get writed to disk.
A new DOS box will appear and you just navigate to the following directory/folder:

Windows\Microsoft.NET\Framework\v2.0.50727\

If you're not used to using DOS you can navigate to it by typing this in the DOS box: cd \windows\Microsoft.net\framework\v2.0.50727 followed by enter.

Then you type in this line: aspnet_regsql.exe -E -S localhost -d Northwind -A all -sqlexportonly c:\membership.sql again followed by enter. At the location c:\ a new file gets generated: membership.sql.

The Northwind name in the parameter list is later on used to set the db name in the generated sql file: SET @dbname = N'Northwind'

Once generated you can use/tweak this file to be used in SSMS to get executed and to install everything needed in the database.

Ok, up untill now we focussed on getting everything ready on the database side but we also have to let our ASP.NET 2.0 application know that we're pointing out to another database than the default one. The solution for this is to override the default settings for the LocalSqlServer connectionstring which can be found in the machine.config file.

<add name="LocalSqlServer"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"

providerName="System.Data.SqlClient" />

To override that you open the web.config file in your application which can be normally found in the root of the application. Go to the <connectionStrings> element.

<connectionStrings>
    <remove name="LocalSqlServer"/>
    <add name="LocalSqlServer" connectionString="The connection string to your
                         (new) database"
providerName="System.Data.SqlClient" />
</connectionStrings>

Notice the second line where you call the remove statement. This is needed in order to be able to override the LocalSqlServer connection string!

If you're in need of a little help to get your connection string right there's a dedicated site: http://www.connectionstrings.com/.

If you're interested in creating one dedicated database for multiple applications you can also check out Scott Guthrie's post: Configuring ASP.NET 2.0 Application Services to use SQL Server 2000 or SQL Server 2005.

Grz, Kris.

Sunday, May 27, 2007 8:46:38 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, April 30, 2007

If you're an ASP.NET developer like me you're going to love this one: Dynamic Datacontrols.

Take a look at the video and be amazed. I can't help to think that it resembles BLINQ a lot although still quite different because that was generated by a tool. This time it depends on the name of the folder and page that you give so that the dynamic controls are able to put together whole pages by themselves. I can't really explain it as well as I would love to but just check out the video. It's cool.

Grz, Kris.

Monday, April 30, 2007 10:10:24 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [2]  |  Trackback
 Sunday, April 01, 2007

Hi,

most ASP.NET developers probably already know that there's a wealth of information to be found under the Learn tab of the ASP.NET website. There's video material covering these subjects:

“How Do I?” with ASP.NET AJAX
“How Do I?” with ASP.NET
SQL Server 2005 Express for Beginners
Videos for ASP.NET 2.0 Beginners
“First Look” Videos
Videos on Visual Studio 2005 Add-ins
Videos on Migrating to ASP.NET

Also I found out that there's also some other interesting video material out there: http://blogs.interfacett.com/dan-wahlins-blog/. It has several nice videos on creating and calling web services, C# delegates & events, creating a webservice with WCF, ... Be sure to check it out.

Grz, Kris.

Technorati tags: , ,

kick it on DotNetKicks.com

 | 
Sunday, April 01, 2007 7:50:40 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Saturday, March 03, 2007

Microsoft provides since recently a new learning center for the beginning developer. Totally dedicated to the freely available Expression editions of Visual Studio 2005 people who are interested in beginning to learn to program can take advantage of.

You can find the Learning Center here.

Another interesting piece of information are the SQL Server 2005 Express For Beginners screencasts.

Grz, Kris.

kick it on DotNetKicks.com

 

Saturday, March 03, 2007 9:50:15 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, January 15, 2007

Hi,

last saturday I already wrote about the new anti XSS library and I just found out there's a dedicated forum for all your question available. Take a look here: Anti-Cross Site Scripting Library.

Grz, Kris.

Monday, January 15, 2007 8:19:48 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Saturday, January 13, 2007

Microsoft recently release the new version of their Anti-Cross Site Scripting (XSS) Library, currently at version 1.5. You can download and find more information about it here. If you're concerned about security in ASP.NET give this library a try.

Grz, Kris.

kick it on DotNetKicks.com

Saturday, January 13, 2007 11:08:37 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Thursday, January 04, 2007

Hi,

I always like to recommend these tutorials to people who are taking their first steps with ASP.NET 2.0. Since I have a couple days off I thought, why not take the lessons myself? The first tutorial shows how to use TableAdapters, which was something I never used before, so it also turned out to be very interesting for me too.

You can find the data tutorials here.

The next weekend and weeks I hope to spend some time on ASP.NET AJAX as well.

Grz, Kris.

Thursday, January 04, 2007 1:25:38 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Sunday, October 29, 2006

The freely available tool WebMatrix, which I used on my old pc to develop ASP.NET pages several years ago, came with a built in webserver, code named Cassini, so a developer could test his/her pages on the localhost.

With the .NET 2.0 framework this localhost only webserver's shipped and if you don't have Visual Studio 2005, or the free Visual Web Developer Express Edition tool (which is the follow up of WebMatrix), you can still execute your pages and view the outcome in a browser.

Here's a little guide on how to proceed:

Create a folder on your hard drive. In this example I created c:\MyASPNETPages\ where my testpage will reside. The testpage itself contains this code:

    1 <%@ Page Language="C#" %>

    2 

    3 <script runat="server">

    4 

    5     protected void Page_Load(object sender, EventArgs e)

    6     {

    7         Label1.Text = DateTime.Now.ToShortDateString();

    8     }

    9 

   10 </script>

   11 

   12 <html>

   13 <head runat="server">

   14     <title>Test Page</title>

   15 </head>

   16 <body>

   17     <form id="form1" runat="server">

   18     <div>

   19         <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

   20     </div>

   21     </form>

   22 </body>

   23 </html>

Now start up a DOS box (Start | Run, type in cmd followed by enter). Navigate to the folder C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

If you don't know how to do this you can type in the following in the opened DOS box:
cd \windows\microsoft.net\framework\v2.0.50727

After that you can type in the text in bold:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>webdev.webserver /port:8088 /path:
"c:\MyASPNETPages" /vpath:"/Test"

Ok what does this mean?

webdev.webserver is the executable itself with the following arguments: port, path and vpath. Port and vpath are optional parameters. After typing the previous lines in bold in and pressing enter a webserver starts up (Figure 1):


Figure 1: Started up webserver

From Figure 1 we can also see what our url will look like (http://localhost:8088/Test).
This demonstrates the purpose of the port and vpath arguments. Port is the port number on which the server will listen. The default is 80 but if you have IIS running, like me, it's better to use another number or they will conflict.

 

After starting the webserver I can easily navigate to my webpage by typing in the url in the address bar of my browser: http://localhost:8088/Test/

As you would've expected I get to see the current date displayed in my page.

If I ommit the vpath argument it would default to "/", meaning that I can navigate to my pages by just typing in this in the address bar: http://localhost:8088/test.aspx

Grz, Kris.

Sunday, October 29, 2006 1:05:19 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, October 23, 2006

Setting the Width property of a control in ASP.NET is mostly done in the properties pane or by declaratively setting it in the markup. However sometimes you want to set it in code. This can be done by using the Unit structure.

I crafted some small example that you can run to play around with the different UnitType enumerations. Possible choises are:

Cm Measurement is in centimeters. 
Em Measurement is relative to the height of the parent element's font. 
Ex Measurement is relative to the height of the lowercase letter x of the parent element's font. 
Inch Measurement is in inches. 
Mm Measurement is in millimeters. 
Percentage Measurement is a percentage relative to the parent element. 
Pica Measurement is in picas. A pica represents 12 points. 
Pixel Measurement is in pixels. 
Point Measurement is in points. A point represents 1/72 of an inch. 

The sample provided here loops over the possible unit types and fills up the dropdownlist. The second textbox is used to fill in an amount to set the Width of the first textbox control to. If you don't fill in an amount it automatically defaults to 30.

    1 <%@ Page Language="C#" %>

    2 

    3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    4 

    5 <script runat="server">

    6 

    7     protected void Page_Load(object sender, EventArgs e)

    8     {

    9         if (!Page.IsPostBack)

   10         {

   11             // Set the original width to 300 pixels

   12             TextBox1.Width = new Unit(300);

   13 

   14             // Loop over the possible unit types

   15             foreach (string s in Enum.GetNames(typeof(UnitType)))

   16                 DropDownListSelectUnitType.Items.Add(Enum.Format(typeof(UnitType), Enum.Parse(typeof(UnitType), s), "G"));

   17         }

   18     }

   19 

   20     protected void Button1_Click(object sender, EventArgs e)

   21     {

   22         // Obtain the chosen width, if it's not filled it default to 30

   23         int width = !String.IsNullOrEmpty(TextBoxSetWidth.Text) ? Convert.ToInt32(TextBoxSetWidth.Text) : 30;

   24 

   25         // Obtain the chosen unit type

   26         UnitType type = (UnitType)Enum.Parse(typeof(UnitType), DropDownListSelectUnitType.SelectedItem.Text, true);

   27 

   28         // Use the Unit structure to set the width of the textbox

   29         TextBox1.Width = new Unit(width, type);

   30     }

   31 </script>

   32 

   33 <html xmlns="http://www.w3.org/1999/xhtml" >

   34 <head runat="server">

   35     <title>Untitled Page</title>

   36 </head>

   37 <body>

   38     <form id="form1" runat="server">

   39     <div>

   40         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />

   41         <br />

   42         <br />

   43         Width: <asp:TextBox ID="TextBoxSetWidth" runat="server" Width="40px"></asp:TextBox><br />

   44         Type: <asp:DropDownList ID="DropDownListSelectUnitType" runat="server">

   45         </asp:DropDownList><br />

   46         <asp:Button ID="Button1" runat="server" Text="Set Textboxes width" OnClick="Button1_Click" />

   47     </div>

   48     </form>

   49 </body>

   50 </html>

Grz, Kris.

Monday, October 23, 2006 10:05:53 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |