Tuesday, March 26, 2013

IOC (Inversion of Control)

I've been doing MVC dev work for a while now, but I'm still pretty new to OOP and a lot of the cool stuff that .NET makes available. One concept that I'm still having trouble internalizing is IOC, or inversion of control. A lot of books cover it to a certain degree, but Code Rant did a great job of breaking it down into practical examples.

Sunday, July 03, 2011

Plus ├ža change...

Another year, another post! My company began using the Razor view engine in all new projects within a few weeks of the MVC 3.0 release and, after spending a few weeks working with it, I came away impressed. However, I'll be starting a new job a week from tomorrow, so it remains to be seen how extensively they use MVC there.

Friday, September 17, 2010

MVC 2.0

The migration from Classic ASP to ASP.NET MVC 2 / .NET Framework 4 at work began several months ago, after two of our devs finished rewriting some of our core legacy tech using C#/.NET. So while things have taken longer than expected, it's still nice to see progress in any form.

I recently picked up Steven Sanderson's "Pro ASP.NET MVC 2 Framework" book from Amazon, and even though I've only read through the first 40 pages, it's been great so far.

Tuesday, September 15, 2009

I.... Live.

It seems my office is going to start migrating from Classic ASP to ASP.NET MVC beginning sometime in Q1 2010. That's assuming our CEO signs off on it -- which he really should, since VBScript is a dead language and I'd rather scoop my eyes out with a melon-baller than keep using it.

In the meantime, though, I'm finally starting to use .NET on-the-job. In fact, after I finish posting this I need to figure out how to convert a normal C# class into a web service using Visual Studio 2008. But so far, I'm loving C# even though I'm still fumbling my way through the basics: how to use the static keyword properly, handling errors, etc.

Tuesday, October 09, 2007

Completely Disabling ViewState in an ASPX Page

As an unabashed ASP.NET novice, I like to ease my way into new things -- the less unknown variables that enter the picture, the easier it is to identify the source of any problems that arise. And one of these new things that I don't yet feel comfortable with is ViewState.

Yes, it's great that you don't have to worry about repopulating your page's data, but there are still plenty of problems that can occur if it's not used properly. One of those issues that I've already run into is page bloat: if there's a lot of information that needs to be "remembered" across round-trips to the server, the information stored in the hidden, client-side ViewState variable will be massive.

I forget where I gleaned this information from, when I figured this out a few months ago, but I'm posting it here before I forget. I completely disable ViewState in an ASPX page's codebehind (C# v2.0) by adding three methods at the top of the class declaration, before the Page_Load() method:


public partial class yourClassName : System.Web.UI.Page {
#region Completely disable page viewstate.
override protected void SavePageStateToPersistenceMedium(object viewState) { }

override protected object LoadPageStateFromPersistenceMedium() {
    object returnValue = null;
    return (returnValue);
}

override protected object SaveViewState() {
    object returnValue = null;
    return (returnValue);
}

#endregion

protected void Page_Load(object sender, EventArgs e) {
    // Your normal ASPX.CS code
}
}


I'm still not aware of all the potential repercussions of using this, so please feel free to comment if you run into any problems.

Tuesday, February 13, 2007

Installing Visual Studio 2005 SP1 on Windows Server 2003

I was trying to upgrade our installation of Visual Studio .NET 2005 to Service Pack 1 last week, when I received an error like this:
Error 1718 - File 1234.tmp was rejected by digital signature policy.

After a bit of Googling, I came across two posts on Heath Stewart's blog which exactly described my problem and provided a workaround. Here's a quick summary of how to install SP1 for Visual Studio 2005 on Windows Server 2003:

1. If you belong to a domain, leave it and reboot your machine.

2. Open up the Registry Editor (Start > Run > regedt32) and navigate to HKEY_LOCAL_MACHINE > SOFTWARE > Policies > Microsoft > Windows > Safer > CodeIdentifiers.

3. With the CodeIdentifiers folder highlighted in the left content pane, check to see if an entry called PolicyScope exists in the right content pane. If it does not yet exist, right-click the CodeIdentifiers folder in the left content pane and select New > Key > DWORD Value. Rename the new item to PolicyScope.

4. Right-click the PolicyScope key in the right content pane, select Modify and change the value to 1.

5. Open up a command prompt (Start > Run > cmd), type net stop msiserver and press Enter to stop the Windows Installer service.

6. Install Service Pack 1 for Visual Studio .NET 2005.

7. If you had to create the PolicyScope key in Step #3, delete it. If the PolicyScope key was already there when you opened up the registry, change its value to 0, using the steps described in Step #3.

8. If you had to leave a domain in Step #1, rejoin it and reboot your machine.

I'm hoping these type of problems go away by the time Service Pack 2 is ready. But for now, I'm just glad I was able to install SP1 without too much difficulty. Thanks, Heath!

Thursday, February 08, 2007

Fixing Intellisense in Web.config

A few days after I began reading Pro ASP.NET 2.0 in C# 2005, I ran into a problem that disabled Intellisense when working in Web.config. It seems I'm not the only one to have experienced this problem: Scott Guthrie and Tim Gaunt, whose blogs I frequent, encountered the same issue.

The problem was that the following line of code in Web.config:
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

Should be:
<configuration>

The xmlns property appears to be inserted every time the Web Site Administration Tool is used. Anyway, I did some digging around and found an answer posted by Massimo Prota in the comments section of Scott Guthrie's blog post about the same problem. Here's what Massimo suggests:

1. Open the folder %windir% \ Microsoft.NET \ Framework \ v2.0.50727 \ ASP.NETWebAdminFiles \ App_Code.

2. In the above folder, open WebAdminPage.cs and in the SaveConfig method (line 93), change the value of config.NamespaceDeclared to false.

UPDATE - Massimo's suggestion didn't fix the problem for me: the xmlns property is still added to my Web.config every time I change something in the IIS Website Name > Properties > ASP.NET > Edit Configuration screen. However, if anybody finds that it does work for them under Windows Server 2003, please let me know...