Posts Tagged ‘.NET’

Optional parameters and named parameters in C# 4.0

One little quirk of C#, which has pretty much become a defining characteristic of the language, is the default parameters system, or lack thereof.

If you want to have a default set of arguments for a function or constructor then you have to create several overloaded versions of the function for each possible set of parameter that you want to be able to accept.

This will no longer be the case in C# 4.0 with the addition of optional parameters and named parameters features. This is one little change I am really looking forward to in a big way.

Read more »

Friendly URLs in an ASP.NET app

Friendly URLs are a great way to improve SEO, promote linking and generally make your web application look more professional. If you have already hopped on to the MVC bandwagon then you don’t need to worry about it, friendly URLs are one of the great many benefits to using ASP.NET MVC. However, if you are still using web forms you will have to go through a couple extra steps to get the same effect.

Just in case you don’t know what a friendly url is, “friendly URLs” (aka “Pretty URLs”, “Beautiful URLs”, “URL Rewriting”, “URL Mapping”, “SEO URLs”, etc.)  I am talking about pages or resources that are identified by keywords in a pseudo-directory structure. For Example, you have a web application with a search page. In a standard web forms application your URI will probably look something like this:

http://your.address/Search.aspx?query=friendly

In a friendly URL structure, your URI would look something like this:

http://your.address/search/friendly

This is a much leaner and cleaner looking link. Really better in every way, though if you are still using ASP.NET web forms you will have to go through some trouble to make your links look like that. As well as having to deal with maintaining the rules and code to support it. It may very well not be worth the trouble.

If your web application is consumer facing and relies on search engines for traffic then you should probably implement friendly URLs in some form for your app.

Read more »

External templates for the DataView control: Microsoft Ajax Library 4.0

One of the best things about templates is how portable they are. You can build a template for a particular piece of presentation and then use that template everywhere you need it. In fact you can have several templates to choose from, giving you themes and different ways of displaying the same data.

This is a very powerful and very maintainable technique. Portable template files are a great example of the Don’t Repeat Yourself (DRY) principal and are a good idea for any template that will see reuse.

The new DataView control in the latest beta of the Microsoft Ajax Library version 4.0 (aka the ASP.NET AJAX Library) has a fine template engine built into it. Unfortunately, those templates must be embedded in the page markup. If it’s your project then you can simply use an ascx User Control, or a ContentPlaceHolder or an Html.RenderPartial, but what if you need to be able to use the template on a static file, or a clients site, or even in another framework? You can’t have portable template files that you can just call anywhere. Well, you can, but you have to use a workaround technique.

This is one technique that I came up with for importing a template file into a page. This lets me have one (or a selection of) template files that I can use everywhere for a portable JavaScript widget. It has no dependencies other than the Microsoft Ajax Library.

Read more »

Reporting of unhandled exceptions in your distributable .NET desktop application

If you’re writing a .NET desktop application that you intend to distribute then you may find it very helpful to build a system for reporting any exceptions that end-users experience back to you. Being able to gather raw exception reports from an app somewhere in the wild will make it much easier to find problems that never appeared on your development and testing environments.

This can save you a lot of headaches when dealing with users complaining about problems that you simply cannot reproduce. An error reporting system has the added benefit of improving end-user morale. It makes people feel much better when they know the developer has received a real report about the problem they encountered.

My method for handling exceptions and reporting them is very simple. However, it does require a little extra work to setup. I’ll walk you through my particular method and give you the basic C# code that I use.

Read more »

PHP needs an IDE and a membership provider

For the last few years I have spent more time working in the .NET framework than I do PHP. It’s not that I don’t like PHP, quite the opposite, I love PHP. However, it seems most of the work I’ve been seeing is for the .NET Framework. And there is a reason for that, .NET is more powerful in terms of pure control, the Visual Studio IDE is absolutely awesome for working with large solutions, and the .NET library provides so many powerful tools.

PHP has a lot going for it, it is powerful, scale-able, easy to work with, and free. The LAMP (Linux Apache MySQL PHP) solution is the standard on the internet. And for a good reason! It’s cheap, it’s fast, it’s memory efficient, and it is very secure (if run by a capable admin). I prefer to work on LAMP systems because I can lock it down so well with tools that are well tested and maintained, and to top it off Linux hosting is cheap!

But PHP does have some drawbacks. A large PHP project can be a nasty endeavor to catch up on. As a developer I always find it difficult coming into a PHP project and trying to figure out what is where. The conventions are simply the whims of whatever the original developer(s) were used to (sometimes none at all).

Read more »