Queens Dev
Some more ASP.NET

Upcoming Blog Posts

March 17, 2009 at 1:24 AM by bjsetegn

Continuing the theme of lists, here is a list of some upcoming blog posts:

  • Regex.Unescape - Why is it useful?
  • Dynamic BlackBerry Optimized Grid - Ever wondered how to make a very dynamic grid?  How about one optimized for the BlackBerry browser?

System.Net.Mail - Command Not Implemented

September 19, 2008 at 5:20 AM by bjsetegn

While setting up the e-mailing features int log4net for an ASP.NET 2.0 project I kept receiving the following exception:

System.Net.Mail.SmtpException: Command not implemented. 
 The server response was: Command not implemented
   at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
   at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
   at System.Net.Mail.SmtpClient.GetConnection()
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
   at log4net.Appender.SmtpAppender.SendEmail(String messageBody)
   at log4net.Appender.SmtpAppender.SendBuffer(LoggingEvent[] events)

I found this troubling because I had used this feature before and had no problem sending e-mails from other applications.  Also another developer was able to use the same exact log4net code on their machine and it worked.  It turned out that the host I was using wasn't setup for relaying e-mails through their e-mail server.  When I used the .NET 1.1 System.Web.Mail classes with the same e-mail server and configuration I would not receive the exception.  It uses a slightly different communication protocol (HELO vs EHLO) that doesn't require relaying to be setup on the e-mail server. So if all else fails and you get the Command Not Implemented exception you could always use the .NET 1.1 System.Web.Mail class.

More Info

http://msexchangeteam.com/archive/2004/02/19/76432.aspx - For setting up an email server for relaying.

http://code.msdn.microsoft.com/KB913616 - For a possible hotfix.

ASP.NET Web.Config Inhertiance - Problem and Solution

March 17, 2008 at 5:35 AM by bjsetegn

While trying to get a Samples section of this website up and running I ran into a couple of problems.  When creating a virtual directory in IIS that was physically under the main application (QueensDev\Samples being the location of the subdirectory) I got an error that one of the Blogengine modules wasn't found.  I thought this was odd because the Samples section didn't use any Blogengine dll's at all. 

Turns out that any application that is in a subdirectory of another application in IIS will inherit all properties from the parent web.config.  This can be highly desirable in certain situations but it wasn't what I was suspecting since it was a separate application in the subdirectory.  It was a problem for me because the subdirectory doesn't contain all the dll's refrenced in the parent directory which was causing my app not to load.  I believe it was trying to find the HTTPModules and Handlers.

I ended up using the solution below.  Wrap system.web in the web.config with the location tag, self explantory.  However, VS2005 and 2008 don't seem to like the location tag but it works just fine. I found this at:

http://aspadvice.com/blogs/ssmith/archive/2006/08/21/HttpModule-Breaks-SubApplications-Problem-Solved.aspx 

<location path="." inheritInChildApplications="false" allowOverride="true">
    <system.web> ...

    </system.web>
 </location> 

More info can be found here:

http://blogs.infragistics.com/blogs/ambrose_little/archive/2007/06/20/isolating-web-settings-from-sub-applications-using-inheritinchildapplications.aspx 

http://msdn2.microsoft.com/en-us/library/ms178685.aspx 

ASP.NET Scroll Position, Page Flicker and Back Button History - Smart Navigation Functionality.

March 16, 2008 at 6:35 AM by bjsetegn

Well for some reason Microsoft decided to deprecate the smart navigation functionality in ASP.NET 2.0 and further (this is old news).  They probably just don't want to spend the time maintaining custom javascript to handle these things in all the different browsers.  This was a great feature when it worked.  You should now use MaintainScrollPositionOnPostBack which does what it says it does and thats it.  It doesn't have all the functionality of SmartNavigation but should work better.  Still haven't found a good solution for Page flicker when loading pages yet other than using AJAX but Microsoft has a couple of ideas.

More info can be found here:

http://support.microsoft.com/kb/913721 

Tags:

ASP.NET

ASP.NET - Repeater vs Datalist vs Gridview

March 14, 2008 at 8:33 AM by bjsetegn

There's a whole lot to be said about the Repeater, Datalist, and Gridview controls and I think it best if they speak for themselves.  So below is a simple page with a repeater, datalist, and gridview.  Each control loads the same sample data to show how they each render.  You can download the code below to take a look at how they each get created.  There are best practices tips in there as well.  Asking what the difference is between these three controls is a great question in an interview with a junior level developer.  If they know when and how to use each they have a mastered the basics of ASP.NET.

Also when taking a look at the link below take a look at the page source.  A great tool for this if you don't have it yet is Firebug.  It will make developing and styling and ASP.NET page 10x easier.

Repeater, Datalist, and Gridview Sample Page:

http://www.queensdev.net/Samples/RepeaterDataListGridview.aspx

To run the sample simply extract the files in the zip to their own folder, open Visual Studio 2005 or 2008, go to File->Open->Website and open the folder you extracted the files to.

Sample code can be found here:

RepeaterDatalistGridview.zip

Tags: ,

ASP.NET | C#