asp.net

There are 74 entries for the tag asp.net

ASP.NET MVC 3 Preview 1 Released

Feels like just yesterday that we released ASP.NET MVC 2 to the world and here I am already talking about an early preview. In a way, we’re right on schedule. It was almost exactly a year ago that we released Preview 1 of ASP.NET MVC 2. Today I’m happy to announce that ASP.NET MVC 3 Preview 1 is available for download. Give it a try out and let us know what you think. Some key notes before you give it a whirl: ASP.NET MVC 3 Preview 1 tooling requires Visual Studio 2010 ...

Null Or Empty Coalescing

In my last blog post, I wrote about the proper way to check for empty enumerations and proposed an IsNullOrEmpty method for collections which sparked a lot of discussion. This post covers a similar issue, but from a different angle. A very long time ago, I wrote about my love for the null coalescing operator. However, over time, I’ve found it to be not quite as useful as it could be when dealing with strings. For example, here’s the code I might want to write: public static void DoSomething(string argument)...

Three Hidden Extensibility Gems in ASP.NET 4

ASP.NET 4 introduces a few new extensibility APIs that live the hermit lifestyle away from the public eye. They’re not exactly hidden - they are well documented on MSDN - but they aren’t well publicized. It’s about time we shine a spotlight on them. PreApplicationStartMethodAttribute This new attribute allows you to have code run way early in the ASP.NET pipeline as an application starts up. I mean way early, even before Application_Start. This happens to also be before code in your App_code folder (assuming you have any code in there) has been compiled. To use...

Globalizing ASP.NET MVC Client Validation

One of my favorite features of ASP.NET MVC 2 is the support for client validation. I’ve covered a bit about validation in the following two posts: ASP.NET MVC 2 Custom Validation covers writing a custom client validator. Localizing ASP.NET MVC Validation covers localizing error messages. However, one topic I haven’t covered is how validation works with globalization. A common example of this is when validating a number, the client validation should understand that users in the US enter periods as a decimal point, while users in Spain will use...

ASP.NET MVC Tabular Display Template

The ASP.NET MVC2 templates feature is a pretty nice way to quickly scaffold objects at runtime. Be sure to read Brad Wilson’s fantastic series on this topic starting at ASP.NET MVC 2 Templates, Part 1: Introduction. As great as this feature is, there is one template that’s conspicuously missing. ASP.NET MVC does not include a template for displaying a list of objects in a tabular format. Earlier today, ScottGu forwarded an email from Daniel Manes (what?! no blog! ;) with a question on how to accomplish this. Daniel had much of it implemented, but was trying to get over...

Putting the Con (COM1, LPT1, NUL, etc.) Back in your URLs

One annoyance that some developers have run into with ASP.NET MVC is that certain reserved filenames are not allowed in URLs. Often, this is manifested as a Bad Request error or a File Not Found (404) error. The specifics of this restriction are accounted for in an interesting blog post entitled Zombie Operating Systems and ASP.NET MVC. This actually wasn’t a restriction on ASP.NET MVC but was built into the core of ASP.NET itself. Fortunately, ASP.NET 4 fixes this issue with a new setting. In web.config, simply add <httpRuntime relaxedUrlToFileSystemMapping="true"/> to the system.web node. Here’s a snippet from my...

Using AntiXss As The Default Encoder For ASP.NET

This is the third in a three part series related to HTML encoding blocks, aka the <%: ... %> syntax. Html Encoding Code Blocks With ASP.NET 4 Html Encoding Nuggets With ASP.NET MVC 2 Using AntiXss as the default encoder for ASP.NET Scott Guthrie recently wrote about the new <%: %> syntax for HTML encoding output in ASP.NET 4. I also covered the topic of HTML encoding code nuggets in the past as well providing some insight into our design choices for the approach we took. A commenter to Scott’s blog post asked, ...

Ms-PL Source Release for System.Web.Mvc 2

Hot on the heels of the release of ASP.NET MVC 2 yesterday, I’m happy to announce that we are releasing the source code to ASP.NET MVC 2 under the Ms-PL license, an OSI approved Open Source license. This continues the trend from nearly a year ago when we released ASP.NET MVC 1.0 under the Ms-PL. You can read my blog post there to learn more about the hard work that goes into such releases. While I’m one who loves lawyer jokes, I do appreciate the work that they do (one of my best friends is a lawyer) and...

ASP.NET MVC 2 Released!

It’s that time of year again when the sakura (cherry blossoms) bloom and allergies kick into high gear. When the drive home is no longer shrouded in darkness and when the ASP.NET team releases Software! Earlier today we released the RTM of ASP.NET MVC 2 for Visual Studio 2008 SP1. See Scott Guthrie’s announcement about it. For download and install options, visit the ASP.NET MVC Download Page. Here are a few helpful resources to help you learn more about this release. What’s New in ASP.NET MVC 2 Upgrading an ASP.NET...

Austin Texas The Techie Town

If there’s one impression that Austin left on me, besides the one that Rudy’s “extra moist” barbecue left on my gut, is that it’s a developer friendly town. This past week I spent three days in Austin meeting with all sorts of developers and had many great conversations about technology. I met with companies and people with a passion for technology that couldn’t be suppressed. Meeting with Dell The reason I was in town was to give a couple of presentations at a mini-conference for Dell employees. On my first day in Austin, the day...

Manipulating Action Method Parameters

During the MVP summit, an attendee asked me for some help with a common scenario common among those building content management systems. He wanted his site to use human friendly URLs.   http://example.com/pages/a-page-about-nothing/ instead of   http://example.com/pages/123/ Notice how the first URL is descriptive whereas the second is not. The first URL contains a URL “slug” while the second one contains the ID for the content, typically associated with the ID in the database. This is easy enough to set up with routing, but there’s a slight twist. He still wanted the action method which...

ASP.NET MVC 2 Optional URL Parameters

If you have a model object with a property named Id, you may have run into an issue where your model state is invalid when binding to that model even though you don’t have an “Id” field in your form. The following scenario should clear up what I mean. Suppose you have the following simple model with two properties. public class Product { public int Id { get; set; } public string Name { get; set; } } And you are creating a view...

Installing ASP.NET MVC 2 RC 2 on Visual Studio 2010 RC

As many of you have probably heard, the release candidate for Visual Studio 2010 was recently released containing immense performance improvements and tons of bug fixes. Another thing that release contains is the release candidate for ASP.NET MVC 2. However, that release is not the latest release of ASP.NET MVC 2 as we recently released a second release candidate for ASP.NET MVC 2 in response to customer feedback. I apologize for the confusion this may have caused, but we really felt it was important to have another release candidate for ASP.NET MVC to help verify that we were...

ASP.NET MVC 2 RC 2 Released

Today I’m pleased to announce the availability of Release Candidate 2 for ASP.NET MVC 2. After receiving feedback from our last release candidate back in December, we decided it would be prudent to have one more release candidate that incorporated the feedback. You can read the release notes for everything that changed, there’s not a whole lot. The biggest change in this release was described by Brad Wilson in his blog post on Input Validation vs. Model Validation in ASP.NET MVC. Also included in this release are an assortment of bug fixes and performance improvements. The window...

ASP.NET MVC 2 and Visual Studio 2010

When we released ASP.NET MVC 2 Beta back in November, I addressed the issue of support for Visual Studio 2010 Beta 2. Unfortunately, because Visual Studio 2010 Beta 2 and ASP.NET MVC 2 Beta share components which are currently not in sync, running ASP.NET MVC 2 Beta on VS10 Beta 2 is not supported. The release candidate for ASP.NET MVC 2 does not change the situation, but I wasn’t as clear as I could have been about what the situation is exactly. In this post, I hope to clear up the confusion (and hopefully...

ASP.NET MVC 2 RC Released

Paternity leave is not all fun and games. Mostly it’s soothing an irate baby and toddler while dealing with explosive poo episodes. Believe me when I say the term “blow out” is apt. That’s probably not the imagery you were hoping for in a technical blog post, but I think you can handle it. ;) What!? It’s already time for an RC?! I think I need to be changed. While I’m on leave, the ASP.NET MVC team continues its hard work and is now ready to announce the release candidate for ASP.NET MVC 2. Go get it now! ...

Localizing ASP.NET MVC Validation

This is the fourth post in my series on ASP.NET MVC 2 and its new features. ASP.NET MVC 2 Beta Released (Release Announcement) Html.RenderAction and Html.Action ASP.NET MVC 2 Custom Validation Localizing ASP.NET MVC Validation In my recent post on custom validation with ASP.NET MVC 2, several people asked about how to localize validation messages. They didn’t want their error messages hard-coded as an attribute value. It turns out that it’s pretty easy to do this. Localizing error messages...

ASP.NET MVC 2 Custom Validation

UPDATE: I’ve updated this post to cover changes to client validation made in ASP.NET MVC 2 RC 2. This is the third post in my series ASP.NET MVC 2 Beta and its new features. ASP.NET MVC 2 Beta Released (Release Announcement) Html.RenderAction and Html.Action ASP.NET MVC 2 Custom Validation In this post I will cover validation. No, not that kind of validation, though I do think you’re good enough, you’re smart enough, and doggone it, people like you. Rather, I want...

Html Encoding Code Blocks With ASP.NET 4

This is the first in a three part series related to HTML encoding blocks, aka the <%: ... %> syntax. Html Encoding Code Blocks With ASP.NET 4 Html Encoding Nuggets With ASP.NET MVC 2 Using AntiXss as the default encoder for ASP.NET One great new feature being introduced in ASP.NET 4 is a new code block (often called a Code Nugget by members of the Visual Web Developer team) syntax which provides a convenient means to HTML encode output in an ASPX page or view. <%: CodeExpression %> ...

Put Your Views (and Pages) On a Diet

One of the complaints I often here with our our default view engine and Pages is that there’s all this extra cruft in there with the whole page directive and stuff. But it turns out that you can get rid of a lot of it. Credit goes to David Ebbo, the oracle of all hidden gems within the inner workings of ASP.NET, for pointing me in the right direction on this. First, let me show you what the before and after of our default Index view (reformatted to fit the format for this blog). Before ...

Single Project Areas With ASP.NET MVC 2 Preview 1

UPDATEThis post is now obsolete. Single project areas are a core part of ASP.NET MVC 2. Preview 1 of ASP.NET MVC 2 introduces the concept of Areas. Areas provide a means of dividing a large web application into multiple projects, each of which can be developed in relative isolation. The goal of this feature is to help manage complexity when developing a large site by factoring the site into multiple projects, which get combined back into the main site before deployment. Despite the multiple projects, it’s all logically one web application. One piece of feedback I’ve already heard...

ASP.NET MVC For Visual Studio 2010 Beta 1

This post is now outdated I apologize for not blogging this over the weekend as I had planned, but the weather this weekend was just fantastic so I spent a lot of time outside with my son. If you haven’t heard yet, Visual Studio 2010 Beta 1 is now available for MSDN subscribers to download. It will be more generally available on Wednesday, according to Soma. You can find a great whitepaper which describes what is new for web developers in ASP 4 which is included. One thing you’ll notice is that ASP.NET MVC is not included...

Donut Hole Caching in ASP.NET MVC

A while back, I wrote about Donut Caching in ASP.NET MVC for the scenario where you want to cache an entire view except for a small bit of it. The more technical term for this technique is probably “cache substitution” as it makes use of the Response.WriteSubstitution method, but I think “Donut Caching” really describes it well — you want to cache everything but the hole in the middle. However, what happens when you want to do the inverse. Suppose you want to cache the donut hole, instead of the donut? I think we should nickname all of...

TipJar: Title Tags and Master Pages

There are a couple of peculiarities worth understanding when dealing with title tags and master pages within Web Forms and ASP.NET MVC. These assume you are using the HtmlHead control, aka <head runat="server" />. The first peculiarity involves a common approach where one puts a ContentPlaceHolder inside of a title tag like we do with the default template in ASP.NET MVC: <%@ Master ... %> <html> <head runat="server"> <title> <asp:ContentPlaceHolder ID="titleContent" runat="server" /> </title> </head> ... What’s nice about this approach is you can set the title tag...

CSRF Attacks and Web Forms

In my last blog post, I walked step by step through a Cross-site request forgery (CSRF) attack against an ASP.NET MVC web application. This attack is the result of how browsers handle cookies and cross domain form posts and is not specific to any one web platform. Many web platforms thus include their own mitigations to the problem. It might seem that if you’re using Web Forms, you’re automatically safe from this attack. While Web Forms has many mitigations turned on by default, it turns out that it does not automatically protect your site against this specific form of...

Anatomy of a Cross-site Request Forgery Attack

A Cross-site request forgery attack, also known as CSRF or XSRF (pronounced sea-surf) is the less well known, but equally dangerous, cousin of the Cross Site Scripting (XSS) attack. Yeah, they come from a rough family. CSRF is a form of confused deputy attack. Imagine you’re a malcontent who wants to harm another person in a maximum security jail. You’re probably going to have a tough time reaching that person due to your lack of proper credentials. A potentially easier approach to accomplish your misdeed is to confuse a deputy to misuse his authority to commit the dastardly act...

ASP.NET MVC 1.0 Released!

Today I’m happy to write that ASP.NET MVC 1.0 RTW (Release To Web) is now officially released. This was one of several announcements ScottGu made at the Mix 09 conference today, which I unfortunately missed because I was on a plane to Vegas enroute to Mix 09. I was busy  back at the mother ship making sure everything was in order for the release. Woohoo! It’s been nearly a year and a half since I joined Microsoft and started working on it and what a ride it’s been. Some highlights during that time: ...

Take Charge of Your Security

Today I read something where someone was comparing Web Forms to ASP.NET MVC and suggested that Web Forms does a lot more than ASP.NET MVC to protect your site from malicious attacks. One example cited was that Server controls automatically handled HTML encoding so you don’t have to really think about it. The idea here is that Web Forms automatically protects you from XSS attacks. My friends, I’m afraid this is just not true. Take a look at the following page code. <%@ Page Language="C#" Inherits="System.Web.UI.Page" %> <% //For demo purposes,...

Routing for Web Forms in ASP.NET 4.0

A while back on a lark, I posted a prototype demonstrating how one could use Routing within Web Forms. This is something you can do today with ASP.NET 3.5 SP1, because of the work we did to separate Routing from ASP.NET MVC. I would have liked to include Web Form Routing as part of the Routing feature when we were working on SP1, but we didn’t have the time to do so in a robust manner before SP1 was locked down. Since then, Scott Galloway, who just happens to be my office mate, has taken the reigns and is...

Combining JQuery Form Validation and Ajax Submission with ASP.NET

As I mentioned before, I’m really excited that we’re shipping jQuery with ASP.NET MVC and with Visual Studio moving forward. Just recently, we issued a patch that enables jQuery Intellisense to work in Visual Studio 2008. But if you’re new to jQuery, you might sit down at your desk ready to take on the web with your knew found JavaScript light saber, only to stare blankly at an empty screen asking yourself, “Is this it?” See, as exciting and cool as jQuery is, it’s really the vast array of plugins that really give jQuery its star power. Today...

Refreshing ASP.NET Dynamic Language Support

This afternoon we released a refresh of our DLR/IronPython support for ASP.NET, now called “ASP.NET Dynamic Language Support”, on our CodePlex site. This was originally part of our July 2007 ASP.NET Futures package, along with several other features. As updates to these features were made available, we would have liked to remove them from the package, but we wanted to wait till everything within the package was updated. Well that time has come. This CodePlex release contains two exceedingly simple sample applications, one for WebForms and one for ASP.NET MVC. It’s compiled against the latest DLR assemblies, and...

ASP.NET MVC CodePlex Preview 5 Released

Download the MSI and Release notes here. Last night we released ASP.NET CodePlex Preview 5 on CodePlex. Be on the lookout for one of those famous epic blog posts from ScottGu describing the release. In the meanwhile, the release notes contain short write-ups of what has changed. We didn’t originally plan to have another preview. However, we implemented a few significant chunks of functionality and were dying to get feedback so that we could incorporate it into the product before Beta. It helps that with five or so of these interim releases, we’ve become pretty efficient producing...

HttpModule For Timing Requests

Yesterday, I wrote a quick and dirty ASP.NET HttpModule for displaying the time that a request takes to process. Note that by turning on trace output for a page, you can get timing information for that page. But as far as I understand, and I need to double check this, this only applies to the page lifecycle, which might not have all the information you want in the context of ASP.NET MVC. Not to mention, I just wanted to see a simple number at the end of the page and not have to wade through all that trace output....

RouteEvaluator For Unit Testing Routes

A while back I wrote a routing debugger which is useful for testing your routes and seeing which routes would match a given URL. Rob suggested we have something like this for unit tests, so I whipped something simple up. This is a class that allows you to test multiple different URLs quickly. You simply create the RouteEvaluator giving it a collection of routes and then GetMatches which returns a List<RouteData> containing a RouteData instance for every route that matches, not just the first one. Here's a sample of usage. [Test] public void CanMatchUsingRouteEvaluator() { var routes = new RouteCollection(); GlobalApplication.RegisterRoutes(routes); var...

Code Based Repeater for ASP.NET MVC

Not long ago, my compadre Scott Hanselman related the following story... In a recent MVC design meeting someone said something like "we’ll need a Repeater control" and a powerful and very technical boss-type said: "We’ve got a repeater control, it’s called a foreach loop." I beg to differ. I think we can do better than a foreach loop. A foreach loop doesn’t help you handle alternating items, for example. My response to this story is, “The foreach loop is not our repeater control. Our repeater control is an iterating extension...

Upcoming Changes In Routing

Made a few corrections on having default.aspx in the root due to a minor bug we just found. Isn’t preview code so much fun? We’ve been making some changes to routing to make it more powerful and useful. But as Uncle Ben says, with more power comes more responsibility. I’ll list out the changes first and then discuss some of the implication of the changes. Routes no longer treat the . character as a separator. Currently, routes treat the . and / characters as special. They are separator characters. The upcoming release of routing will only treat the...

My First IronRuby Unit Test Spec For ASP.NET MVC

Way down the road, it would be nice to be able to build ASP.NET MVC applications using a DLR language such as IronRuby. However, enabling DLR language support isn’t free. There are going to be places in our design that are specific to statically typed languages (such as Attribute based filters) that just wouldn’t work (or would be too unnatural) with a dynamic language. Ideally we can minimize those cases, and for the ones we can’t, we need to make sure the extensibility of the framework allows for extending the system in such a way that we can provide a DLR friendly...

ASP.NET Routing Debugger

In Scott Hanselman’s wonderful talk at Mix, he demonstrated a simple little route tester I quickly put together. This utility displays the route data pulled from the request of the current request in the address bar. So you can type in various URLs in the address bar to see which route matches. At the bottom, it shows a list of all defined routes in your application. This allows you to see which of your routes would match the current URL. The reason this is useful is sometimes you expect one route to match, but another higher up the stack matches instead. This...

Using Routing With WebForms

UPDATE: I updated the sample to work with the final version of ASP.NET Routing included with ASP.NET 3.5 SP1. This sample is now being hosted on CodePlex. Download the demo here In my last post I described how Routing no longer has any dependency on MVC. The natural question I’ve been asked upon hearing that is “Can I use it with Web Forms?” to which I answer “You sure can, but very carefully.” Being on the inside, I’ve had a working example of this for a while now based on early access to the bits. Even so, Chris Cavanagh impressively beats me to...

Thoughts on ASP.NET MVC Preview 2 and Beyond

At this year’s Mix conference, we announced the availability of the second preview for ASP.NET MVC which you can download from here. Videos highlighting MVC are also available. Now that I am back from Mix and have time to breathe, I thought I’d share a few (non-exhaustive) highlights of this release as well as my thoughts on the future. New Assemblies and Routing Much of the effort and focus of this release was put into routing. If you’ve installed the release, you’ll notice that MVC has been factored into three assemblies: ...

Abstract Base Classes Have Versioning Problems Too

This is part 2 in an ongoing series in which I talk about various design and versioning issues as they relate to Abstract Base Classes (ABC), Interfaces, and Framework design. In part 1 I discussed some ways in which ABCs are more resilient to versioning than interfaces. I haven’t covered the full story yet and will address some great points raised in the comments. In this part, I want to point out some cases in which Abstract Base Classes fail in versioning. In my last post, I mentioned you could simply add new methods to an Abstract Base Class and not...

Versioning Issues With Abstract Base Classes and Interfaces

Eilon Lipton recently wrote a bit about context objects in ASP.NET MVC and in an “Oh by the way” moment, tossed out the fact that we changed the IHttpContext interface to the HttpContextBase abstract base class (ABC for short). Not long after, this spurred debate among the Twitterati. Why did you choose an Abstract Base Class in this case? The full detailed answer would probably break my keyboard in length, so I thought I would try to address it in a series of posts. In the end, I hope to convince the critiques that the real point of...

ASP.NET MVC Update

By the way my blogging frequency has declined, you can guess I’ve been quite busy here at Microsoft preparing for the next release of ASP.NET MVC. It’s not just working on specs, design meetings, etc... that keep me busy. It’s preparing for several talks, various spec reviews, building hands on labs, demo and and app building, etc...that keeps me busy. All the while I am still learning the ropes and dealing with selling a house in L.A. and buying a house up here. There’s a lot that goes into being a PM I naively didn’t expect, on top...

Blocking Direct Access To Views in ASP.NET MVC

UPDATE: I improved this based on some feedback in my comments. With ASP.NET MVC it is possible for someone to try and navigate directly to a .aspx view. In general, this only leaves them with an ugly error message as Views typically need ViewData in order to work. However, one approach that I think will easily work is to create a Web.config file in the root of your Views directory that contains the following. We need to do more testing on our side to make sure there's no pathological case in doing this, but so far in my personal testing, it seems to...

Come Work With Me And Other Great People

The ASP.NET and Silverlight team are hiring! Brad Abrams (who happens to be my “grand-boss” as in my boss's boss) posted a developers wanted ad on his blog: Are you JavaScript guru who has a passion to make Ajax easier for the masses? Are you the resident expert in ASP.NET and consistently think about how data driven applications could be easier to build? Are you a TDD or patterns wonk that sees how ASP.NET MVC is a game-changer? Are you excited about the potential of...

Get A Free Copy Of Our New Book

I just received a few advanced copies of our new book and am giving away three of them to the first three people who leave a comment on this post. But there’s a catch! You have to have a blog and promise to write a review on your blog. This is on the honor system so I’ll send you the book and you can then review it. In your comment, leave your email address in the email field (it’s not visible to anyone else) and I’ll follow up to get your mailing address. Also let me know if you want...

Buy Our Book And Become An ASP.NET Bad Ass

Remember the book I mentioned that I was writing along with a few colleagues? Well it is finally available for pre-order on Amazon.com! If you love me, you’ll buy five copies each. No. Ten copies! Or, you could wait for the reviews and buy the book on its own merits, which I hope it warrants. But what’s the fun in that? All kidding aside, this was a fun and tiring collaborative effort with Jeff “Coding Horror” Atwood, Jon Galloway, K. Scott Allen, and Wyatt Barnett. The book aggregates our collective wisdom on the topic of building web applications with...

Conditional Compilation Constants and ASP.NET

UPDATE: K. Scott Allen got to the root of the problem. It turns out it was an issue of precedence. Compiler options are not additive. Specifying options in @Page override those in web.config. Read his post to find out more. Conditional compilation constants are pretty useful for targeting your application for a particular platform, environment, etc... For example, to have code that only executes in debug mode, you can define a conditional constant named DEBUG and then do this... #if DEBUG //This code only runs when the app is compiled for debug Log.EverythingAboutTheMachine(); #endif It’s not common knowledge to me that these constants...

IHttpContext And Other Interfaces For Your Duck Typing Benefit

Not too long ago I wrote a blog post on some of the benefits of Duck Typing for C# developers. In that post I wrote up a simplified code sample demonstrating how you can cast the HttpContext to an interface you create called IHttpContext, for lack of a better name. Well I couldn’t just sit still on that one so I used Reflector and a lot of patience and created a set of interfaces to match the Http intrinsic classes. Here is a full list of interfaces I created along with the concrete existing class (all in the System.Web namespace except...

Cleanup The Crap That Windows Live Writer Injects With This HttpModule

First, let me start off with some praise. I really really like Windows Live Writer. I’ve praised it many times on my blog. However, there is one thing that really annoys me about WLW, it’s utter disregard for web standards and the fact that injects crap I don’t want or need into my content. Of particular annoyance is the way that WLW adds attributes that are not XHTML compliant. For example, when you use the Insert Tags feature, it creates a div that looks something like: <div class="wlWriterEditableSmartContent" id="guid1:guid2" contenteditable="false" style="padding-right: 0px; display: inline; padding-left: 0px;...

Securely Implement ELMAH For Plug And Play Error Logging

ELMAH, which stands for Error Logging Modules and Handlers for ASP.NET, is an open source project which makes it easy to log and view unhandled exceptions via its pluggable architecture. Having been around a while, a lot has already been written on it so I won’t rehash all that information. For more details, you can read the following: Using HTTP Modules and Handlers to Create Pluggable ASP.NET Components ELMAH page on Google Code All you need to know for the purposes of this post is that ELMAH is implemented as two key components: An HTTP Module Used...

Open Source On .NET Is Not An Oxymoron

I have a confession. I am an Open Source developer and my platform of choice is the .NET framework by Microsoft. Not only that, I actually believe it is a good thing to support Open Source projects in the Microsoft ecosystem. Yeah, really. In response to this tidbit, I have heard and am bracing to hear replies such as... Why would you do that (support Open Source on Microsoft)? Or It can’t be Open Source if it’s on the Microsoft platform. One rationale given is that it ain’t really Open Source unless the entire stack is Open Source. I call this the all or nothing...

Unit Test Web Code Without A Web Server Using HttpSimulator

Testing code written for the web is challenging. Especially code that makes use of the ASP.NET intrinsic objects such as the HttpRequest object. My goal is to make testing such code easier. A while ago, I wrote some code to simulate the HttpContext in order to make writing such unit tests easier. My goal wasn’t to replace web testing frameworks such as Selenium, Watin, or AspUnit. Instead, I’m a fan of the Pareto principle and I hoped to help people easily reach the 80 of the 80/20 rule before reaching out to one of these tools to cover...

How To Handle The DIV Tag Around ASP.NET Hidden Inputs

One praiseworthy aspect of ASP.NET 2.0 is its much improved XHTML compliance. However, there is one particular implementation detail related to this that causes some web designs to break and could have been implemented in a better manner. The detail is how ASP.NET 2.0 will wrap a DIV tag around hidden input fields. My complaint isn’t that Microsoft added this DIV wrapper, because it is needed for strict compliance. My complaint is that there is no CSS class or id on the DIV to make it easy to exclude CSS styling on it. For example, here is a snippet from the output of...

GMail-like Loading Indicator with ASP.NET Ajax

Simone Chiaretta, a member of the Subtext development team (among other open source projects), has been quite busy lately. I recently mentioned the Vista Sidebar Gadget for CruiseControl.NET he published. He also was recently in a video interview by MindBlog. Go Simo! The post that caught my eye recently is how to make a Gmail-like loading indicator with ASP.NET Ajax. This is a nice demonstartion of how to use the ASP.NET Ajax library to simulate various styles of user interface. Personally though, I’m not a fan of this particular loading indicator at the page level. When I have my...

CSS Control Adapters Double PostBack Issue

My Coworker (and Subtext co-admin) Steve Harman writes about a weird double PostBack issue he ran into recently when using CSS Friendly Control Adapters with the CreateUserWizard Membership Provider control. So far he hasn’t received much in the way of feedback in the forums yet. Have any of you run into this? Technorati tags: ASP.NET, CSS

Databinding Tips: Nesting Eval Statements

Maybe this is obvious, but it wasn’t obvious to me. I’m binding some data in a repeater that has the following output based on two numeric columns in my database. It doesn’t matter why or what the data represents. It’s just two pieces of data with some formatting: 42, (123) Basically these are two measurements. Initially, I would databind this like so: <%# Eval("First") %>, (<%# Eval("Second") %>) The problem with this is that if the first field is null, I’m left with this output. , (123) Ok, easy enough to fix using a format string: <%# Eval("First", "{0}, ") %>(<%# Eval("Second") %>) But now I’ve learned that...

Where Should You Place Your Labels In Your Form

UPDATE: Luke Wroblewski posted a link in my comments to his Best Practices for Form Design PDF. It is 100+ pages chock full of good usability information concerning forms. Thanks Luke! James Avery writes about the Art of Label Placement in which he links to a few great articles on form design and label placement. Web Application Form Design by Luke Wroblewski - This article covers the best ways to arrange labels and submission buttons. Web Application Form Design Expanded by Luke Wroblewski - Another great article from Luke W. expanding on the same topics. Label Placement in Forms by Matteo...

Gain Control Of Your Control State

Some people think the ViewState is the spawn of the devil. Not one to be afraid of being in bed with the devil, I feel a tad bit less negative towards it, as it can be very useful. Still, it has its share of disadvantages. It sure can get bloated. Not only that, but disabling ViewState can wreack havock with the functionality of many controls. This is why ASP.NET 2.0 introduces the control state. The basic idea is that there is some state that should be considered the data for the control, while other state is necessary for the control to function. For example,...

ASP.NET Tip - Use The Label Control Correctly

Scott Watermasysk has a great set of Quick Tips for ASP.NET on his blog. And this is only part one! I’m Looking forward to seeing the subsequent posts of this series. However, I disagree slightly with his tip to Never use the ASP.NET Label control. I would rephrase it to: Never use the ASP.NET Label control when a Literal would do. The problem is not the Label control. The problem is treating the Label control as if it was merely a Literal control. The Label control has a specific usage, to be a label for a form input. For example, check out this screenshot of...

Identicons as Graphical Digital Fingerprints

How do you uniquely identify a person, without divulging the identity of that person? For example, given a set of personal artifacts, how would I arrange the set of artifacts grouped by the person to which they belonged? The answer is quite easy, isn’t it (especially given the title of this blog post and the image to the right)? You can look at the fingerprints on the items. Unless you happened to have a file that mapped the fingerprints to individuals, you won’t know who the comb and mirror belong to, for example, only that they do belong to the same person and...

HTTP Debugging Using Reverse Proxies And Port Forwarders

I’m currently working on an interesting project to develop a series of HTTP services used by games running on the RIM Blackberry. These services will enable players to compete against one another (though not in real time) in various games and see high scores, challenge friends, etc.... It brings a social aspect to gaming on your blackberry device. The games are written in Java and I’m using a Blackberry emulator for testing the interaction between the game and the services. I’m running the service at localhost on my local machine to allow me to step through the debugger when necessary. ...

Using WebServer.WebDev For Unit Tests

Last night a unit test saved my life (with apologies). Ok, maybe not my life, but the act of writing some unit tests did save me the embarrasment of an obscure bug which was sure to hit when I least expected it.  It is cases like this that made me into such a big fan of writing automated unit tests. Not too long ago I wrote a C# Akismet API for Subtext. In writing the code, I followed design principles focused on making the API as testable as possible. For example, I applied Inversion of Control (IOC) by having the AkismetClient constructor take...

Express Yourself With Custom Expression Builders

One of the hidden gems in ASP.NET 2.0 is the new expression syntax. For example, to display the value of a setting in the AppSettings section of your web.config, you can do this: <asp:Label Text="<%$ AppSettings:AnotherSetting %>" ID="setting" runat="server" /> Notice that the value of the Text property of the Label control is set to an expression that is similar to the DataBinding syntax (<%#), but instead of a pound sign (#) it uses a dollar sign ($). Expressions are distinguished by the expression prefix. In the above example, the prefix is AppSettings.  The...

Adding Client-Side Custom Properties To Controls

One of the benefits of writing an ASP.NET book is that it forces me to spend a lot of time spelunking deep in the bowels of ASP.NET uncovering all sorts of little gems I never noticed the first time around. Many of these little morsels should end up in the book, but I thought I would blog about a few of them as I go along.  This is all part of the weird situation I find myself in while writing this book. I thought I would just sit down and all the words would flow. Instead, no matter how motivated I...

Register Custom Controls In Web.config

This one is probably old news to many of you, but I just recently ran across it. Every time I want to add a new control to a new page, I get annoyed because I have to remember that annoying syntax for registering a control. Let’s see...how does it go again? Do I have to add a TagName attribute? No, that’s for user controls. Hmmm, forget it, I’ll just dynamically add it! Well in the interest of reducing future angst, here are two examples of the syntax, one for a custom control and one for a user...

Atlas Web Application Project Template

Dave (a Subtext developer) just blogged about a project template he created for creating Atlas applications using the Web Application Project (WAP).  This is wicked useful for those of us who prefer Web Application Projects over Web Site Projects. Tags: ASP.NET, Atlas

OriginUrl Supports Regular Expressions

In a recent post I ranted about how ASP.NET denies WebPermission in Medium Trust. I also mentioned that there may be some legitimate reasons to deny this permission based on this hosting guide. Then Cathal (thanks!) emailed me and pointed out that the originUrl does not take wildcards, it takes a regular expression. So I updated the <trust /> element of web.config like so: <trust level="Medium" originUrl=".*" /> Lo and Behold, it works! Akismet works. Trackbacks work. All in Medium Trust. Of course, a hosting provider can easily override this as Scott Guthrie points out in my comments. I need to stop...

Why Oh Why Couldn't WebPermission Be Part Of Medium Trust?

This is a bit of rant born out of some frustrations I have with ASP.NET. When setting the trust level of an ASP.NET site, you have the following options:Full, High, Medium, Low, Minimal It turns out that many web hosting companies have chosen to congregate around Medium trust as a sweet spot in terms of tightened security while still allowing decent functionality. Only natural as it is the one in the middle. For the most part, I am sure there are very good reasons for which permissions make it into Medium trust and which ones are not allowed. But...

A Gotcha Identifying the User's IP Address

Recently I wrote a .NET based Akismet API component for Subtext.  In attempting to make as clean as interface as possible, I made the the type of the property to store the commenter’s IP address of type IPAddress. This sort of falls in line with the Framework Design Guidelines, which mention using the Uri class in your public interface rather than a string to represent an URL.  I figured this advice equally applied to IP Addresses as well. To obtain the user’s IP Address, I simply used the UserHostAddress property of the HttpRequest object like so. HttpContext.Current.Request.UserHostAddress The UserHostAddress property is...

Rolling Your Own Blog Engine

Jeff Atwood asks the question in a recent post if writing your own blog software is a form of procrastination (no, blogging is). I remember reading something where someone equated rolling your own blog engine is the modern day equivalent of the Hello World program.  I wish I could remember where I heard that so I can give proper credit. UPDATE: Kent Sharkey reminds me that I read it on his blog. It was a quote from Scott Wigart. Thanks for the memory refresh Kent! Obviously, as an Open Source project founder building a blog...

Lightweight Invisible CAPTCHA Validator Control

UPDATE: This code is now hosted in the Subkismet project on CodePlex. Not too long ago I wrote about using heuristics to fight comment spam.  A little later I pointed to the NoBot control as an independent implementation of the ideas I mentioned using Atlas. I think that control is a great start, but it does suffer from a few minor issues that prevent me from using it immediately. It requires Atlas and Atlas is pretty heavyweight. Atlas is pre-release right now. We’re waiting on a bug fix in Atlas...

Please Vote On This Atlas Javascript Bug

UPDATE: Looks like this will get fixed in the next release according to a comment on Steve’s blog. Steve Harman, a Subtext developer, was prototyping using Atlas in Subtext and encountered a rather problematic bug. Not only did he encounter the bug, he went through the hard work to dig into the source of the bug right down to the line of code and proposes a fix.  How is that for constructive criticism? Unfortunately, he hasn't received any response from the Atlas team (at the time of this posting) regarding whether or not they recognize this as a bug...

Atlas Comment Spam Heuristics

Remember my recent post in which I suggested that we need more heuristic approaches to the comment spam problem? Check out this new NoBot control in the Atlas Control Toolkit.  I wonder if this came out before or after I wrote my piece, because I don’t want y’all to think I cribbed my ideas from this control.  It has a couple features that I mentioned. Forcing the client’s browser to perform a configurable JavaScript calculation and verifying the result as part of the postback. (Ex: the calculation may be a simple numeric one, or may also involve the...