Permission is granted to reprint/use these on the web so long as there is a link to my website.

Adventures in ASP.NET (2008)

Back to Article Index

After years of creating small simple websites in php, I decided that for a large complex site I preferred a different language. Oh I like PHP but I find development is a bit fiddly. I'm not a full time PHP developer so anytime I do anything I've not done before its hours on the net or wading through books. Though a full-time developer, when it comes to ASP.NET I am a weekend/evening coder and still learning. I can see once I'm up to speed that ASP.NET will be wonderfully productive but it takes a bit of learning!

I started with asp so I thought why not ASP.NET especially as I am reasonably au fait with C#. A friend got me involved in doing his business site which I had started in php. As luck would have it through my writing for, on C, C++ and C# I got a free copy of Visual Studio 2008 Professional. So I bought a couple of books and started climbing a new learning curve.

My First Overhang- CSS & Themes

Doing a site in ASP.NET is a little like Dreamweaver templates. You create a Master Page with all the stuff (menus, links, logo, sidebars etc) then leave gaps for content- a minimum of two sections: one for meta stuff(title, description, keywords) and one for page content. I'd say it's also a bit like Powerpoint master slides which provide a backdrop for the presentation slides. But I have one problem... Why does VS 2008 not show my Master page theme in the editor?

I've created a skin using css from a php website and applied this to my master page, but in VS 2008 it shows as text in the design window. On the live site the pages are rendered correctly! This failure to show the template happens when editing both the mastepage or a content page. Yes I am using code behind and have set it to enable theming. If you know the answer I'd welcome an email via the contact me form.

A Beautiful set of Web Designs

I converted Multiflex-3. One of a series of five web templates that you can find here. These were all designed by a Pastor called Gerhard and I rate them very highly, having converted Multiflex-3 into both PHP and now ASP.NET.

Web.config is fun

This is the XML file at the heart of every ASP.NET application in configuration information etc. But it can be a real pain when switching between local and live web sites. For SQL Server databases you have to setup LocalSqlServer and the connection string.

<remove name="LocalSqlServer"/>
<add name="LocalSqlServer"
connectionString="Data;Initial Catalog=mydbname;User ID=uid;Password=password"
<add name="LocalSqlServer1"
connectionString="Data Source=PCNEW\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=mybname"

The trick I use is to have both but disable the one you don't want with a 1 on the end. Is there a better way? (Programmatically I suppose).

Avoiding ASPNETDB.mdf

So you want to use SQL Server to hold all the data? It really surprised me that the default is to store everything in a MSDE file ASPNETDB.mdf in the App_Data folder. If you want it in a SQL Server database you have to run the aspnet_regsql.exe utility and create a default roles and users etc. You can then add users on the site through registration components (and login). When you are first starting out be sure you haven't created. Look in App_Data and keep it clean.

I do think this approach using MSDE is wrong and a massive waste of time for new web developers. Microsoft should get rid of the MSDE ASPNETDB.mdf file, integrate aspnet_regsql.exe into VS Studio and assume that people will use SQL Server 2005/2008 (or at least the Express version) or MySQL. I guess this came about because VS 2005 was probably out before SQl Server 2005 Express but it's 2008 now chaps so time to update!

The Hosting Server Fun!

I use who are very good on support and I rate them pretty highly for uptime, response etc. Their knowledgebase is a little out of date as it refers to the DTS type instructions for copying databases (more SQL 2000) rather than SQL Server 2005. If you use personalisation to add users and roles to your SQL Server 2005 (or SQL Server 2005 Express) then you cannot copy everything across in one easy go. Not even with SQL Server 2005 (I use the developer version).

With SQL Server 2005 Express your best bet I've found is to script the database and copy tables, views and stored procedures. With developer edition you can export data which copies tables and views. You still need to generate a script for the stored procedures.

The DSN Farago

Sorry Crystaltech, but you screwed up big time with this! The rest of your service is good (its fast and i'm connecting from the UK) which is why I use you but this one needs attention. I can't be the only person to have fallen into the Crystattech DSN (Data Source Name) trap. You create a SQL Server 2005 database via their control panel and then create a dsn to use for it. Only it doesn't work! Oh the control panel test says it works but when you plug it into web.config and use it from an ASP.NET application, it fails to connect. Here's why...

The dsn they gave you is something like this
Put this in web.config and it throws up and doesn't understand dsn. What works is Data Source=dburl;Initial Catalog=yourdbname;User ID=yourusername;Password=yourpassword;network=crystaltechnetworkid Most bizarre. They provide the dburl when you create a database and you can access it across the net. The crystaltechnetworkid is taken from the dodgy dsn. So if you're stuck, try my version.

But what about Roles and schemas?

I made the mistake of copying these across and messing up the database. So I deleted the database and when I recreated it, the dsn was broken in the test. You just have to delete it, then create a new dsn which is identical to the first one (and still wrong!).

Flat Structure Versus Folder

In Php I'm used to having folders and using defines to specify include folder paths. in ASP.NET it's different. You have the pain of testing who can access every file (if using authorization to limit access) against putting a set of files in a folder. But then you have to maintain a web.config in each folder. For now I'm sticking to a flat structure (no pages in folders) but I may change my mind.

--- This is a work in progress and will be periodically updated ---


Back to Article Index

Permission given to reprint/use on the web so long as it includes a link to my website.
If you like this article, share it by bookmarking- click an icon below

Bookmark Adventures in ASP.NET at    Digg Adventures in ASP.NET at    Bookmark Adventures in ASP.NET at    Bookmark Adventures in ASP.NET at    Bookmark Adventures in ASP.NET at    Bookmark Adventures in ASP.NET at NewsVine    Blink this Adventures in ASP.NET at    Bookmark Adventures in ASP.NET at    Fark Adventures in ASP.NET at    Bookmark Adventures in ASP.NET at YahooMyWeb