Posts tagged asp.net

There are 9 posts for the tag asp.net

Visual Studio feature - Preview web.config transforms

On my way to continuous delivery, I often use Visual Studios built-in support for Web.config transformations, at least for relatively simple situations. This allows you to automatically create variations of you web.config file for different deployment environments. And with the help of the excellent Visual Studio plug-in SlowCheetah, you can apply this to other config files as well.This is all great, but I found it a little tricky to verify that my config transformations yielded the expected res...

Posted by johan on November 22, 2013

Accessing an IIS Express site from a remote computer

Sometimes (waaaay to often) I have to check that a site I’m working on looks like it should in Internet Explorer 6, Safari on Mac or some other browser that I can’t run in Windows 7. In this case I wanted to access it from IE6 running in XP Mode.  I could of course deploy it to IIS and make it publicly available, but since I’m now using IIS Express for running my sites from Visual Studio instead of the built-in web server Cassini, it almost simple to let other computers on my network access the ...

Posted by johan on August 16, 2011

An even simpler way not to send email

I thought this was to simple to blog about, but then I read this post by my colleague Daniel Saidi, and I thought “what the hell”. Yes, when developing web applications you very often need to send emails. But during development, or testing for that matter, you often don’t actually want to send any emails. You could, of course, go the interface-injection-way, as in Daniel’s post. But there is actually an even easier way, build into .NET. Just edit the config for system.net/mailsettings. Normal...

Posted by johan on January 28, 2011

Testing DataAnnotation-based validation in ASP.NET MVC

UPDATE: Aaron Jensen pointed out that this only works for .NET 4. The DataAnnotation.Validator class mentioned in the post does not exist in .NET 3.5, so this method does not work. With .NET Framework 3.5 SP1 came DataAnnotations, and with ASP.NET MVC 2 Preview 1 came built-in support for DataAnnotation validation. This makes basic validation, like required fields, number intervals and so on, very simple. In order to be able to test this validation, though, you have to mimic some of the work th...

Posted by johan on November 18, 2009

Lifting an ASP.NET MVC 1.0 project to Visual Studio 2010

I have a pet project (several actually, but let’s stick to one of them). It’s called Önskelistemaskinen, and is a web application for keeping track of the wish lists of my family members. It’s build in ASP.NET MVC with a Linq-to-SQL backend (loosely modelled after Rob Conery’s Storefront project), and naturally grossly overdesigned for an application with a target audience of about 10 people. Anyway, I started working on this when the first beta of ASP.NET MVC came out about a year ago, and wi...

Posted by johan on October 21, 2009

Subtle differences

This post was originally published on http://labs.dropit.se/blogs. Today I hade the dubious pleasure of having to work with an old EPiServer 4 site, and having to deploy it to IIS7 on a Windows 2008 Server. In order to make everything work in EPiServer 4, you need to make sure that all 404-request are redirected to /Util/NotFound.aspx. On my development machine, which runs Windows 7, I accomplished this by adding the following code to web.config: <system.webServer> <httpErrors...

Posted by johan on August 26, 2009

Most misleading error message ever?

This post was originally published on http://labs.dropit.se/blogs. Sometimes .NET error messages are helpful, sometimes they are not. But worst of all are when they are outright misleading! Like the one I came across today. I was trying to programmatically register a ASP.NET Ajax ScriptManager in a web control, and as the webcontrol was already overriding OnPreRender, I figured “what the heck, I’ll just put it there”. So, I basically wrote this code: protected override void OnPreRender( Ev...

Posted by johan on July 08, 2009

Page being loaded twice

This post was originally published on http://labs.dropit.se/blogs. Ever had the problem of pages being loaded twice, that is that all the events are being hit two times? I have, and I've never really been able to figure out why, but I recently stumbled over this old entry at ASP.NET Resources. It seems that it is a problem with AutoEventWireup, or rather it is a problem if you use both AutoEventWireup and wire the events in the codebehind as well. You can read the full story on ASP.NET Resou...

Posted by johan on December 03, 2008

Never use HttpContext to access the Cache!

This post was originally published on http://labs.dropit.se/blogs. This has probably been said a million times, but it's definitely worth saying again. Never use HttpContext.Current.Cache, always use HttpRuntime.Cache.  Why? Because HttpRuntime is always available, even when you're not in a web context (e.g. even in a console app), and HttpContext is not. And it's the exact same Cache! Do you, for example, think that you have access to the HttpContext in a unit test? Probably not. HttpRunti...

Posted by johan on November 28, 2008