Skip navigation
Man climbing a rocky precipice

Exploring ASP.NET: ASP.NET Grab Bag

Thoughts on a hodgepodge of topics relevant to ASP.NET developers

I've been saving up a few things to write about that don't justify an entire article—yet. One of the items is OData, which is topic big enough to fill an entire book… or three. And I'll share with you a pet peeve.

My Favorite New MVC 2 Feature

There is a lot to learn about and love in MVC 2, and I'm loving it all (and I'm not even a big test guy). But my hands-down, absolute new favorite feature is the new RequireHttpsAttribute action filter. You can apply it to either the controller class or one or more action methods. When users make a request affected by the attribute using the http: protocol, they are automatically redirected to use https:. Sweet!

Yet Another Data Access Protocol

Over the course of more than 20 years of doing development with Microsoft technologies, I've seen a lot of data access technologies come and go. And it seems at times as though they are all still with us. There should be a joke in there somewhere. Q: What's the difference between a Microsoft data access technology and a Federal agency? A: Sometimes agencies go away. I'll work on that and get back to you.

Anyway, the latest in this long data access line is OData, short for the Open Data Protocol. A white paper on the site describes it as enabling "the creation of HTTP-based data services, which allow resources identified using Uniform Resource Identifiers (URIs) and defined in an abstract data model, to be published and edited by Web clients using simple HTTP messages." You can use OData with a variety of data sources, not just relational databases.

By the way, ADO.NET Data Services, which was to be a set of services that expose data as resources accessed through URIs, using standard HTTP verbs like GET, POST, etc. (sound familiar?), is now WCF Data Services in the .NET Framework 4.0. It sounds an awful lot like OData without the "open" part.

Maybe I'm finally getting cynical, but I think I'll just hold off and wait to see which of these technologies gains traction, then jump in. No need to rush.

Rethinking Entity Framework

In my last article for asp.netNOW, I wrote about how I was being dragged kicking and screaming to Entity Framework, mostly because Microsoft seems determined to make it everyone's data access layer of choice. It is maturing, so maybe there is hope for it.

But then this week I was stung by the pervasive and stubborn non-nullable default date, out-of-range exception: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. The statement has been terminated. Unfortunately, conversion to DateTime2 in the database is not an option. The problem seems to be that Entity Framework is initializing the date fields to something outside of the valid range of a DateTime (1/1/1753 through 12/31/9999). This is yet another disconnect between .NET and SQL Server.

The only solution seems to be using validation or a constructor to set the default date based on the limitations of the underlying database. Not quite a horrible kludge, but something that shouldn't be necessary. But it is the sort of thing that makes Entity Framework just too darn hard to use, even with the new improvements. I'm not fond of workarounds for common scenarios that haven't been handled from the first days of Entity Framework.

Julie Lerman has a Microsoft Connect item on this that suggests one solution. It's too late to change anything for Entity Framework 4, but maybe if you go and vote on Julie's item Microsoft will consider a solution for this. This has been a persistent problem since the first version of Entity Framework, so they don't seem to recognize it as a pain point.

In the meantime, I'm still moving forward with Entity Framework. But now, it's with much more trepidation.

Favorite New ASP.NET 4 Feature

ASP.NET 4 has a new code comment feature that I'm falling in love with. You can delimiter a comment in a view with <%--  --%> server comments instead of the standard HTML comment delimiters <!--  -->>. When you use server comments, the comment isn't delivered to the user when ASP.NET generates the page. The official benefit is that it makes your HTTP responses more lightweight because comments aren't sent to the user. But the real benefit is that those embarrassing, self-deprecating comments sprinkled throughout all of our code don't get sent to the user as part of the page source. You know, the comments that appear all too frequently in The Daily WTF. Microsoftie Bertrand LeRoy has a post about the comments in his Tales From the Evil Empire blog: Ban HTML comments from your pages and views.

I love server comments!   

Pet Peeve

As we near the launch of Visual Studio 2010, .NET Framework 4.0, and all the related goodies, I've been tearing my hair out anew with a long running pet peeve. When I'm on the bleeding edge and working with updated technologies that are nearing release, I often hunt online for documentation, blog entries, and other resources to help make sense of all the new stuff. With the new Help system in Visual Studio 2010 being so horrible, online resources are going to be all the more important.

My peeve is when someone writes something and puts it online—and this includes Microsoft bloggers—without identifying what version of the technologies they used. It happens all the time and goes something like this. I find the perfect article about something I'm trying to do or a problem I've just got to solve. The description is exactly what I need, and the solution offered is elegant, simple, and will work in my scenario. So I trundle off and implement it in my solution and… nothing. Zilch. It's broken. It causes more problems than I had before.

Turns out that the author was using beta 5 of CTP 14 that was released months ago and superseded several times since then without mentioning that fact. And it seems like most of the time those broken solutions are in articles that aren't dated, so I have no idea it is a year old. (Or, more often, you have to search the fine print in the page for the date, hidden deep in the page, visible only after scrolling down 17 times, after the 354 comments.) Please, everyone who puts stuff online: tell us what version of stuff you're using!

Thanks for letting me get that off my chest. See you next month!

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.