Wednesday 8 September 2010

MVC custom error problem on IIS7



From bitter experience I have now learned (once again) how important it is to test your applications in a staging environment which is different from your development machine.

In this case our problem was customErrors, which looks fantastic on your developer machine, but gets thrown away when you install your application in the IIS 7 server.

Luckily I found this guys post:
IIS 7 Error Pages taking over 500 Errors which describes the problem. Only when you use MVC and do some error handling in the controllers, it doesnt arrive to the Application_Error method, as he describes, but instead you should add the "TrySkipIisCustomErrors" in the OnException in each controller.

protected override void OnException(ExceptionContext filterContext)
{
string viewName = "MyErrorView";
System.Web.HttpContext.Current.Response.TrySkipIisCustomErrors = true;
View(viewName, errorData).ExecuteResult(this.ControllerContext);

}

In any case its always good to do something in the Application_Error method, if nothing else, log any errors which is not handled any other places

Wednesday 30 June 2010

71-515 .NET 4 web application developer

Finaly Microsoft gave me my result of my Beta exam:



I PASSED :D

Visual Studio 2010 cheat sheet

I found the cheat sheet for VS2010: link

Friday 4 June 2010

adding dates to a filename in a bat script

In case others out there need something so prehistoric as making a bat script which adds a date to a filename for ex when creating a back up with 7-zip.

The following worked for me:

call "c:\Program Files\7-Zip\7z.exe" a -tzip %date:~6,4%-%date:~3,2%-%date:~0,2%.%time:~0,2%-%time:~3,2%-zipFile.zip *.dll


will zip files into an archive called:


2010-06-04.15-37-zipFile.zip


Hope it will save you some frustration!

Thursday 4 March 2010

Prealoading Web Applications

On the list of what's new in ASP.NET 4.0 you find "Prealoading Web Applications".

If you are running ASP.NET 4.0 on IIS 7.5 you can ask sites to be preloaded when the Internet server starts up (or restarts).

It sounds cool, and a good thing that you are now able to reload heavy services, but I can help thinking that it is also a solution to a problem which should exist. The IIS should handle the Internet communication, while leaving the heavy data processing to services outside of the IIS. These services would should be implemented as services on the server, No?

70-515. TS: Web Applications Development with Microsoft .NET Framework 4

With the announcement of the .NET 4.0 exams, it seems a bit like a wrong career move not to aim for taking the web application development certificate for 4.0 instead of 3.5, since I have already been working with VS2010 for some time now.

Looking at the Skills Being Measured List it seems like a good idea to continue studying the MCTS Self-Paced Training Kit (Exam 70-562) with a sharp eye to the list of topics.

Hopefully I will be invited to take a beta exam when they come out in April.

I guess a good place to start looking into the ASP.NET 4.0 would be here

Here are some of my comments to the elements of What's new:

Tuesday 9 February 2010

ExecuteScalar doesn't return the return value

One thing to remember when making a stored procedure or just simple SQL, which should be executed thought a call of the ExecuteScalar method in .NET: that ExecuteScalar doesn't actually return the return value but the first column of the first row in the result set, or a null reference if no result is found!

Thursday 7 January 2010

The skitzofrenic DataRow Versions.

The DataRow contains several different versions (DataRowVersion) of the data it contains and several different RowStates, and of top of that it can be in edit mode or not. This can be a bit complicated grasp, in the following I will try to explain to myself (and any other reader) how it works.

The RowState is a description of the rows connection to a DataTable and whether the data is changed.

The different DataRowVersion contains the different versions of the data, and can either be: Current, Original, Proposed or a pointer to one of the three (it is usually denoted as the Default).

And finally a DataRow can be in Edit Mode or not. A DataRow enters and exits this mode when BeginEdit and EndEdit is invoked respectively.

The lifetime of a DataRow can pass through these RowStates:

  1. Detatched: The DataRow is created but not attached to any DataTable.
  2. Added: The RowState goes to Added when it is added to a DataTable.
  3. Unchanged: If the AcceptChanges method is invoked, the RowState becomes Unchanged.
  4. Modified: If the data is modified the RowState becomes Modified, this is however not true if the current RowState is Added.
  5. Deleted: When the Delete method is invoked.


Strangely enough the DataRowVersions doesnt really have anything to do with the RowState, but whether the DataRow is in Edit Mode or not(or well in RowState Deleted.

Before an Edit the default data in the row is found in Current version. In edit mode the default data will be in the Proposed version, while the current version contains the unedited version.
After an Edit the Original version contains the data from before the edit, while the Current version contains the hmm... current version (in other words the Proposed version in Edit mode).