With thanks to http://stackoverflow.com/users/603670/ben-barreth
at http://stackoverflow.com/questions/1981426/how-do-i-mock-fake-the-session-object-in-asp-net-web-forms
[csharp]
[SetUp]
public void SetUpHttpSessionMock()
{
HttpWorkerRequest _wr = new SimpleWorkerRequest("/dummyWorkerRequest", @"c:\inetpub\wwwroot\dummy", "default.aspx", null, new StringWriter());
HttpContext.Current = new HttpContext(_wr);
HttpSessionStateContainer sessionContainer = new HttpSessionStateContainer("id", new SessionStateItemCollection(), new HttpStaticObjectsCollection(), 10, true, HttpCookieMode.AutoDetect, SessionStateMode.InProc, false);
SessionStateUtility.AddHttpSessionStateToContext(HttpContext.Current, sessionContainer);
}
[/csharp]
Tag: asp.net
Asp.net / IIS7 : System.BadImageFormatException: Could not load file or assembly
You have something like this:
Server Error in '/Vendorapplication' Application.
Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
It's because you are trying to run 32 bit dlls on a 64 bit system. Fix it in IIS manager by changing the advanced settings on you application pool to enable 32 bit applications. Or create a new app pool specifically for them.
Alex James Brown has a nice picture: change app pool to 32 bit
There is a duplicate system.web.extensions/scripting/scriptResourceHandler section defined
Scenario:
You've been working with no problems probably in VS2008 on web app written on .net 2 or .net 3.5 or .net 3.5 sp1 and then you try running on a machine with windows 7 or vista running IIS7 and you get this error message...
Simples. It's comes of running your .Net 2 (you did know that a .Net 3.5 app actually runs on .Net 2 didn't you?) app under .Net 4. Fix it by changing the app pool for your web app to the pre-defined "Classic .Net App Pool", which runs .Net framework 3

ASP.NET MVC 2 Localization and Local Resource Files
The complete guide to localization with Global Resources is at While my keyboard gently weeps - ASP.NET MVC 2 Localization complete guide but here's a simple summary:
Using Global Resources for Asp.NET MVC Localization Quick Start
- Create ordinary resource files in your project and fill 'em up.
- Add a Page Import directive to your MVC view:
<%@ Import namespace="My.Project.Name.PathTo.WhereverYourResourceFileIs" %> - Behold the compiled fields available to you in intellisense:
[sourcecode language="xml"]<%=ResourceFileName.MyPropertyName %>[/sourcecode]
Using Local Resources for Asp.NET MVC Localization Quick Start
The net and his dog seems to want to discourage you from using Local resource files with MVC. There are two or three riddles and here's how to solve them:
- Right click your view directory. choose Add -> Add Asp.Net Folder -> App_LocalResources.
- Create resource files in there with names to exactly match the View name (so you end up with MyView.aspx.resx as the file name).
- Change the access modifier from its default No Code Generation to Public
- Type in your resource strings
- Add a Page Import directive to your MVC view:
[sourcecode language="xml"]<%@ Import namespace="My.Project.Name.Views.ViewName.App_LocalResources" %>[/sourcecode]. Get the exact namespace by opening up the Resource File's aspx.Designer.cs file. - While you're in the resource Designer.cs file note the class name: ActionName_aspx
- Behold the compiled fields available to you in intellisense:
[sourcecode language="xml"]<%=ActionName_aspx.MyPageSpecificPropertyName %>[/sourcecode] - Be awed and depressed when you build and run and get the error message ''Could not find any resources appropriate for the specified culture or the neutral culture. Make sure .... etc etc". Fix this by clicking on the resx file in solution explorer and changing its Build Action from Content to Embedded Resource.. (thanks to http://www.devproconnections.com/article/aspnet22/ASP-NET-MVC-Localization for this point).