How to handle the error "The specified string is not in the form required for an e-mail address."

Posted by: Imar Spaanjaars at Saturday, July 18, 2009 1:45:19 PM in: ASP.NET 3.5
Recently I saw a number of people (a colleague and some readers of my book Beginning ASP.NET 3.5 in C# and VB) run into an ASP.NET error indicating that the "specified string is not in the form required for an e-mail address". This error is quite common and usually pops up when developers or end users are supplying a value that doesn't match the syntax rules for an e-mail address. However, in the recent cases I saw this error popped up at the moment a new MailMessage class is constructed. That means the code crashed even before it tried to assign an e-mail address to one of the To, CC, Bcc or From properties through code. So what happened?
Read on ...

Proper Handling of 404 Errors Using redirectMode

Posted by: Imar Spaanjaars at Sunday, July 05, 2009 1:54:35 PM in: ASP.NET 3.5

ASP.NET has a handy feature that lets you easily determine an error page that gets displayed in case an error occurs on your server. Using the customErrors section in the web.config file you can assign specific pages that are displayed for specific HTTP error codes. The following example shows how 404 errors (page not found) and 500 errors (server errors) are routed to the file ~/Errors/Error404.aspx and ~/Errors/Error500.aspx respectively. All other errors are handled by the generic ~/Errors/Error.aspx page:

<customErrors mode="On" defaultRedirect="~/Errors/Error.aspx">
  <error statusCode="404" redirect="~/Errors/Error404.aspx" />
  <error statusCode="500" redirect="~/Errors/Error500.aspx" />
</customErrors>

Although easy to use and set up, this solution has some drawbacks that might impact how search engines see your site and how 404 errors are treated. The good news is: these problems can easily be overcome.

Read on ...

Using a Local Pickup Folder for Email Delivery

Posted by: Imar Spaanjaars at Friday, July 03, 2009 11:12:17 AM in: ASP.NET 3.5
Many of the web applications I build make use of e-mail somehow. Whether it's the ASP.NET Membership services that send out account confirmations or reset passwords, or some custom logic that sends out e-mail, I typically used an SMTP server on my local network or one from an ISP. However, using a remote server isn't the fastest nor most secure way to send mail.
Read on ...

Checking the Existence of an ASP.NET Membership Username with ASP.NET AJAX

Posted by: Imar Spaanjaars at Sunday, June 28, 2009 7:02:26 PM in: ASP.NET 3.5

If you have been using the Membership features that ship with ASP.NET, I'm sure you're familiar with the CreateUserWizard control that lets a user sign up for an account on your site. One of the features of this control (in cooperation with the Membership services) is to check whether a given user name is already taken and display an appropriate message if that's the case. This is an excellent feature as it makes sure no two users can end up with the same user name.

One of the problems with this check is that it takes place at the server. This means the page goes through a full post back which takes some time. Even worse, due to security settings on the control, the two password fields are reset so the user has to enter them again in case they chose an existing user name. It would be a lot easier if you could check the user name before the page is posted back using a bit of client side script. With ASP.NET AJAX and Page Methods, this is a walk in the park.

Read on ...

Extending ValidationBase to Validate Properties of Type ValidationBase

Posted by: Imar Spaanjaars at Sunday, April 26, 2009 3:35:37 PM in: ASP.NET 3.5
A couple of days ago I got an e-mail from Maarten van der Lee with some code that can be used in my Validation Framework of my N-Layer Design article series to validate sub properties whose type is a ValidationBase as well. This can be useful if you want to present a full list of validation errors for an object and its properties.
Read on ...

Introducing Spaanjaars.Validation.SharedAttributes

Posted by: Imar Spaanjaars at Saturday, April 18, 2009 4:41:00 PM in: ASP.NET 3.5
Last week Scott Brady sent me the code for a number of attributes compatible with the validation framework I use in my article series on N-Layer design.
Read on ...

N-Layered Web Applications with ASP.NET 3.5 Part 6: Security

Posted by: Imar Spaanjaars at Monday, March 09, 2009 9:33:00 AM in: ASP.NET 3.5

Note: this is the last part in a series of six. If you rather read this entire series off-line, you can buy the series as a convenient PDF document that comes with the full source. Besides the convenience, buying the PDF will also make you feel good as it shows your appreciation for the articles and helps me pay the bills for my server and hosting so I can keep running imar.spaanjaars.com and continue to provide you with great content. For more details, check out this post that shows you how you can buy the entire series right now.

This is part 6 of a six-part series of articles on N-Layer design. This article series builds on top of my three part series on N-Layer design that I released in early 2007. If you haven’t already done so, be sure to check out these articles first, as a lot of code and concepts used in this new series is explained in detail in the older series.

In this last article in the series, I'll deal with security in your N-Layered web application.

Read on ...

Localizing client side JavaScript

Posted by: Imar Spaanjaars at Tuesday, February 24, 2009 9:34:02 AM in: ASP.NET 3.5

As you may know, my Contact Manager application used in my new series on N-Layer design using ASP.NET 3.5 is fully localizable. That is, the site is available in two languages - English and Dutch - and users can choose the language they want to see the site in. The concepts behind the localization process are all built in to the ASP.NET framework and didn't require a lot of work from my side.

Shortly after I published the article on localization, I received an e-mail from a reader asking how he could use the same principles to translate client side JavaScript. He had written some custom JavaScript code that displayed messages to the user and he wanted an easy way to translate those messages as well. The good news is: it's pretty easy to do....

Read on ...

N-Layered Web Applications with ASP.NET 3.5 Part 5: Dealing with Concurrency

Posted by: Imar Spaanjaars at Tuesday, February 10, 2009 9:40:00 PM in: ASP.NET 3.5

Update!! - I have written a new series on N-Layer design targeting ASP.NET 4.5 and Entity Framework 5. You can check out the new series here.

Note: this is part five in a series of six. If you rather read this entire series off-line, you can buy the series as a convenient PDF document that comes with the full source. Besides the convenience, buying the PDF will also make you feel good as it shows your appreciation for the articles and helps me pay the bills for my server and hosting so I can keep running imar.spaanjaars.com and continue to provide you with great content. For more details, check out this post that shows you how you can buy the entire series right now.

This is part five of a six-part series of articles on N-Layer design. This article series builds on top of my three part series on N-Layer design that I released in early 2007. If you haven’t already done so, be sure to check out these articles first, as a lot of code and concepts used in this new series is explained in detail in the older series.

In this installment, I’ll discuss techniques for dealing with concurrency — I'll show you how to handle data conflicts caused by updates from other users.

Read on ...

N-Layered Web Applications with ASP.NET 3.5 Part 4: Sorting, Paging and Filtering

Posted by: Imar Spaanjaars at Tuesday, January 20, 2009 8:04:08 PM in: ASP.NET 3.5

Update!! - I have written a new series on N-Layer design targeting ASP.NET 4.5 and Entity Framework 5. You can check out the new series here.

Update 02/03/2009: There is now a VB.NET version of the application available thanks to Sven Huijbrechts from ClearMedia bvba. Check it out at the Downloads section at the end of this article

Note: this is part four in a series of six. If you rather read this entire series off-line, you can buy the series as a convenient PDF document that comes with the full source. Besides the convenience, buying the PDF will also make you feel good as it shows your appreciation for the articles and helps me pay the bills for my server and hosting so I can keep running imar.spaanjaars.com and continue to provide you with great content. For more details, check out this post that shows you how you can buy the entire series right now.

This is part 4 of a six-part series of articles on N-Layer design. This article series builds on top of my three part series on N-Layer design that I released in early 2007. If you haven’t already done so, be sure to check out these articles first, as a lot of code and concepts used in this new series is explained in detail in the older series.

In this installment you'll see a few important ways to work with data: Sorting, Paging and Filtering.

Read on ... 1234567891011