:::: MENU ::::

Friday, February 25, 2011

A great little utility called smtp4dev. It's an SMTP server that listens on your local machine, and instead of relaying e-mail, it'll capture them and store them in a queue so you can review and open them.

It's brilliant – simple and elegant and incredibly easy to use. Just configure your application (website, debugger, logging framework – whatever it is you're building) to send mail on localhost:25, fire up smtp4dev, and watch the messages pile up.

Binaries and source are at smtp4dev.codeplex.com – well worth a look if you ever write software that sends e-mail.

 

Thursday, February 24, 2011

Chances are, at some point you've tried creating a new user account on a website and were told that the username you selected was already taken. This is especially common on very large websites with millions of members, but can happen on smaller websites with common usernames, such as people's names or popular words or phrases in the lexicon of the online community that frequents the website. If the user registration process is short and sweet, most users won't balk when they are told their desired username has already been taken - they'll just try a new one. But if the user registration process is long, involving several questions and scrolling, it can be frustrating to complete the registration process only to be told you need to return to the top of the page to try a different username.

Many websites use Ajax techniques to check whether a visitor's desired username is available as soon as they enter it (rather than waiting for them to submit the form). This article shows how to implement such a feature in an ASP.NET website using Membership and jQuery. This article includes a demo available for download that implements this behavior in an ASP.NET WebForms application that uses the CreateUserWizard control to register new users. However, the concepts in this article can be applied to ad-hoc user registration pages and ASP.NET MVC.

Read more!

 

This is one of those simple tip posts that may seem obvious and taken for granted by those of us who have been working with SQL Server for a while now but maybe a newbie or two out there will find this helpful.

 

Every so often (just this morning!) I find myself resetting an identity column value back to 0 after I've deleted all the existing records so the table gets a fresh start at primary key 1. Yes, I know all about primary keys not changing and how the value in the primary key doesn't matter and so on. Sometimes I just like the primary keys starting at 1.

 

The following line resets the Identity value for the Customer table to 0 so that the next record added starts at 1.

 

DBCC CHECKIDENT('Customer', RESEED, 0)

 

Have a day. :-|

 

Thursday, February 3, 2011

WiX toolset v3.5 is now officially declared Production/Stable. The final build number is 3.5.2519.0. You can download it from here.

WiX v3.5 delivers official support for Visual Studio 2010 and IIS7. The standard UI also supports a quite few more languages (but not all of those) and we simplified the WiX language a bit. Plus there are a bunch of bug fixes in WiX v3.5 that makes this release the best version of the core WiX toolset ever released.

 

Friday, January 14, 2011

I'm excited to announce the release today of several products:

  • ASP.NET MVC 3
  • NuGet
  • IIS Express 7.5
  • SQL Server Compact Edition 4
  • Web Deploy and Web Farm Framework 2.0
  • Orchard 1.0
  • WebMatrix 1.0

The above products are all free. They build upon the .NET 4 and VS 2010 release, and add a ton of additional value to ASP.NET (both Web Forms and MVC) and the Microsoft Web Server stack.


More

Download Microsoft Web Platform Installer

 

 

Wednesday, December 15, 2010

Anyone doing ASP.NET development probably admits, openly or not, to introducing or stumbling upon a security issue at some point during their career. Developers are often pressured to deliver code as quickly as possible, and the complexity of the platform and vast number of configuration options often leaves the application in a less than desirable security state. In addition, the configuration requirements for debugging and production are different, which can often introduce debugging settings in production, causing a variety of issues.

Over the years, the ASP.NET platform has matured and better documentation has been made available through MSDN and community blogs, but knowing which feature or configuration setting to use is often troublesome. Even with good knowledge of the security functionality, mistakes can happen that could result in security vulnerabilities in your application.

Peer code review is a useful process and a good way to catch issues early. Still, not everyone has the time or budget—or knowledgeable peers at hand—for such review.

Since the introduction of code analysis in Visual Studio 2005, developers have been able to automatically analyze their code to see if it complies with a series of best practices ranging from design, maintainability, performance and security. So far, code analysis has been a great tool, but it hasn't focused on providing best security practice guidance for ASP.NET—until now.

In this article I'll introduce you to the new ASP.NET code analysis rules that can be used with Visual Studio code analysis as well as with the standalone FxCop application to improve the security of your ASP.NET applications.

Overview

You can download the ASP.NET security code analysis rules package for Visual Studio 2010 and FxCop version 10.0 from go.microsoft.com/?linkid=9750555. The installation contains three new rules packages:

  • ASP.NET.Security: This category focuses on security best practices related to how System.Web.Ui.Page properties are initialized.
  • ASP.NET.MVC.Security: This category focuses on security best practices related to how ASP.NET MVC is used.
  • ASP.NET.Security.Configuration: This category focuses on security best practices related to configuration elements under the web.config files.

Once the rules package is installed, you can start reviewing the security of your Web application automatically by clicking on the Run Code Analysis on Web Site button under the Build menu (see Figure 1). The analysis will review each Page class and web.config file of your application against a series of security best practices for ASP.NET.

More

 

Monday, December 13, 2010

Today we are announcing the release of GhostDoc v3.0 - a new major release of the product. This version includes product usability and menu changes, adds many new features - menus, configuration rules, configuration options. It also features new error logging to improve troubleshooting of GhostDoc issues. The new version introduces GhostDoc Pro Edition - enhanced version of the product that gives users complete control over your XML Comment content and layout as well as automates XML Comment generation via batch actions.

For Edition comparison please see GhostDoc product page - http://submain.com/ghostdoc/

New in v3.0:

  • (Pro Only) New Document Type feature - generates XML comments for the entire type/class
  • (Pro Only) New Document File feature - generates XML comments for the entire file
  • (Pro Only) Introduced T4 template based rules that replace rule macros of the Free version
  • Improved support for VS2010
  • New Load/Unload menu items allow to disable GhostDoc temporary without uninstalling it
  • New Help menu item
  • New option to and menu to Re-assign Shortcut
  • Added Rule for read-only property to turn off generation of the tag line
  • Added Rule for private constructor
  • Added support for new tags - <inheritdoc>, <author> and <remarks>
  • Added support for enums, delegates and fields
  • Added option to modify Configuration Folder path
  • Added option to Keep Single Line when for long comments
  • Changed leading tabs to leading spaces for compatibility with other products
  • Changed "gets or sets" summary prefix to just "Gets" when setter is private
  • Fixed automatically implemented properties issue 

GhostDoc and GhostDoc Pro build 3.0.10340 are available for download right now at http://submain.com/download/ghostdoc/

Please note GhostDoc EULA was updated to reflect the introduction of GhostDoc Pro.

Download More

 

Thursday, November 18, 2010

As you may already know, it is easy to come up with a document - the key is in implementing these standards in your organization, through methods like internal trainings, Peer Reviews, Check in policies, Automated code review tools etc. You can have a look at FxCop and/or StyleCop for automating the review process to some extent, and can customize the rules based on your requirements.

Anyway, here is a list of some good Coding Standard Documents. They are useful not just from a review perspective - going through these documents can definitely help you and me to iron out few hidden glitches we might have in the programming portion of our brain.

So, here we go, the listing is not in any specific order.

1 – IDesign C# Coding Standards

IDesign C# coding standards is a pretty decent and compact (27 pages) Coding Standards Document. It covers a Naming conventions, Best practices and Framework specific guidelines. Example:

The document even has guidelines for project settings, build configuration, versioning etc. Good work by IDesign guys. You can download the document here

2 – Encodo C# Handbook

Encodo C# handbook is bit more recent, and has 72 pages of guidelines on Structure, Formatting, Naming. It also has a 'Patterns and Best Practices' section, which is a must read for any .NET/C# developer.

You can download the Handbook here.

3 – Microsoft Framework Design Guidelines

MSDN has a section on guidelines for Designing class libraries, which covers a set of best practices related to Type Design, Member Design etc. You can find it here.

4 – Denni's C# Coding Standards document

Dennis created an initial version of C# coding standards, which was published as Philips Health Care C# coding standards document (~70 pages). The document categorizes the guidelines to categories like Naming, Exception Handling, Control Flow etc.

  • Update: Dennis kindly pointed that the Initial Version I linked here earlier has now been superseded by the Coding Guidelines for C# 3.0 and C# 4.0. Paul Jansen of Tiobe will update his site soon regarding the new version - But in meantime, download the guidelines and some companion documents here: http://csharpguidelines.codeplex.com/

5 – Microsoft's All-In-One Code Framework Coding Guideline

Microsoft's All In One Code framework has a Coding Style Guideline document. The Microsoft All-In-One Code Framework is a free, centralized code sample library provided by the Microsoft Community team. It has typical code samples for all Microsoft development technologies, and a code style guideline document with that. Thanks to Kevin for pointing out this guideline document with All In One Code Framework (See the comments)

6 – Brad's Quick Post on Microsoft Internal Coding Guidelines

Brad had a post on Microsoft Internal coding standards (I'm not sure whether he still follow that in Google, if at all he uses C# there). It is a short post, and is mainly on Styling and Naming conventions.

7 – Mike's C# Coding Style Guide

Mike Kruger (Sharpdevelop) had published a 13 page C# Coding Style guide. Again, the focus is on Casing, Naming conventions, Declaration style etc. A short and simple Style Guide.

So, if you are still confused about which document to choose - my recommendation is here for you - Based on your landscape, organizational climate, project and domain, go through these documents and pick the relevant recommendations – to formulate your very own 10 page '.NET/C# Coding standards/guidelines' for your team.

Also, if you think I missed any prominent guideline document, list down the same in the comments section, and I'll include that in the main post if it is relevant – My initial post was about 6 documents, but I expanded/modified the list later based on some feedback I received. Happy Coding.

More

 

Monday, September 27, 2010

Most projects I work on need a list of countries at some point so I put together a snippet of SQL that I could reuse to create and populate a countries table in the database with all countries as given in ISO 3166-1. After recently writing a utility class to populate list controls with world currencies according to ISO 4217 it got me wondering if I could also do the same for countries using only the .Net Framework. And so I came up with the following utility class to do the job.

        /// <summary>
        /// Populates the list control with countries as given by ISO 4217.
        /// </summary>
        /// <param name="ctrl">The list control to populate.</param>
        public static void FillWithISOCountries(ListControl ctrl)
        {
            foreach (CultureInfo cultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
            {
                RegionInfo regionInfo = new RegionInfo(cultureInfo.LCID);
                if (ctrl.Items.FindByValue(regionInfo.TwoLetterISORegionName) == null)
                {
                    ctrl.Items.Add(new ListItem(regionInfo.EnglishName, regionInfo.TwoLetterISORegionName));
                }
            }
 
            RegionInfo currentRegionInfo = new RegionInfo(CultureInfo.CurrentCulture.LCID);
 
            //- Default the selection to the current cultures country
            if (ctrl.Items.FindByValue(currentRegionInfo.TwoLetterISORegionName) != null)
            {
                ctrl.Items.FindByValue(currentRegionInfo.TwoLetterISORegionName).Selected = true;
            }
        }

More Info

Working with SQL Server over the years has made me realize just how much learning I have to do before I can classify myself a database guru.  Along the way, I have learned a lot of cool things from various sources, but still have plenty more areas to study.  Most of the things that I've learned about SQL Server, as well as many other things, have come from a need for a solution to a particular situation.  What I will be discussing today came from one of those situations.

The problem I had to solve involved querying the database with several different parameter options.  The same data was to be retrieved with each query, but it was the filtering of the data that changed.  My initial reaction was to write a stored procedure for each of the different parameter permutations.  The problems with that approach are numerous, so let's just say it was too much of a waste of time.  I started looking for alternatives and found this blog post discussing the basics of just what I needed to do.  Since I'm using this blog as a way for me to archive some of the cool things I've learned, I'll put my own spin on the topic here.

The basics are this: make a single stored procedure that will take in all the possible parameters, giving each one a default value of NULL in case it is not needed, and return the necessary data filtered accordingly.  Sound simple?  Actually, it really is.  Here is an example of a stored proc that does just that:

CREATE PROCEDURE GetCrap
    @CategoryID int = NULL,
    @MinPrice decimal(4,2) = NULL,
    @MaxPrice decimal(4,2) = NULL
AS
BEGIN
    SELECT *
    FROM TableWithCrap T
    WHERE (@CategoryID IS NULL OR T.CategoryID = @CategoryID) AND
          (@MinPrice IS NULL OR T.Price >= @MinPrice) AND
          (@MaxPrice IS NULL OR T.Price <= @MaxPrice)
END 

See how simple it is?  Simply give the optional parameters a default NULL value (@CategoryID int = NULL).  Then, and here's the cool part, make each part of the WHERE clause a conditional that will either evaluate to true if the parameter is null or evaluate according to the requirement.

@CategoryID IS NULL

will return true if the parameter CategoryID has not been given, thus eliminating it from the filtering process.

@CategoryID IS NULL OR T.CategoryID = @CategoryID

basically says, "if I have a value, use me."

That's it!  AND those bad boys together and you've got a respectable dynamic query built right into a nice stored procedure!  Isn't that cool?

More Info