|
I'm just starting to work with ASP.NET, and I immediately ran into a problem that had me stumped until a more experienced coworker discovered a fix.
I wrote a very simple ASP.NET web application, and tried to deploy it -- i.e. to put it into its intended location on my machine. The folder where the application is deployed is not the same as the folder where the project is located. More importantly, I tried to get it to run under Internet Information Services, as opposed to under the temporary "ASP .NET development server" that Visual Studio 2005 creates for debugging purposes. (It ran just fine under the ASP .NET development server.) Here is what I did and the errors I ran into.
Let's say my little application is called Foo. I created it from the Visual Studio 2005 template for web sites, by going to File->New->Web Site, and then selecting "ASP .NET Web Site" from Visual Studio installed templates. Then I followed these instructions from the ASP.NET reference book on how to deploy an ASP .NET web site.
1. With the Internet Services Manager open, right-click on the Default Web Site and select New and then Virtual Directory. The Virtual Directory Creation Wizard Opens; it walks you through the steps of creating a virtual directory.
2. First, the wizard asks you to provide an alias -- that is, the name of the virtual directory. When someone is accessing your site, the alias will be in the following location: http://localhost/Alias.
Although my ASP.NET project is called Foo, I will call my virtual directory Foovirt. (I prefer to use different names for different things, even if they can in principle have the same name. That way when I get error messages, I can easier identify the source of the problem.) And I don't have a Default Web Site in IIS on my machine; instead, the web site under which Foo will run is called Bar.
So, I right-click on the Bar web site in the IIS Manager, select New, and then Virtual Directory. The wizard asks me to provide an alias. I enter Foovirt.
3. The wizard then asks for the hard physical directory where the files for your application are located. If the application files are not present on the machine yet, choose the directory where they will be located after they are installed.
The physical directory where the application files will be located is c:\Foo. So I enter c:\Foo in the wizard where it asks to specify the physical directory.
4. Next, the wizard asks you to specify access permission to the side. Choose the default values for now; you can modify them later, if needed.
The default values don't include the "Run Scripts" permission. It seems I would need to enable this permission in order to run ASP scripts. So I checked this checkbox. In addition, the default checkbox "Read" is checked. So, I am allowing the following permissions: "Read" and "Run scripts (such as ASP)".
Then I clicked "Next" in the wizard, and got a message "You have successfully created a virtual directory".
The book says all I need to do to deploy my application is copy all the files created by the project to the physical directory that's associated with this virtual directory. So I copied all the files and folders from its initial location at
C:\Documents and Settings\<my_username>\My Documents\Visual Studio 2005\WebSites\Foo
to c:\Foo. Those files are Default.aspx, Default.aspx.cs, and the folder App_Data -- in other words, files and folders that were created by the Visual Studio 2005 web site template.
I should now be able to run my script at the URL http://localhost/Foovirt/Default.aspx. Instead I get this error message:
Server Error in '/Foovirt' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this
request. Please review the following specific parse error details and modify your source
file appropriately.
Parser Error Message: Could not load type '_Default'.
Source Error:
Line 1: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
Line 2:
Line 3:
Source File: C:\Foovirt\Default.aspx Line: 1
Now I'm thinking, maybe I should have precompiled my website. In Visual Studio 2005 the only command that lets you precompile your website is the Build->Publish Website command. So I will use this option.
The dialog box that opens with the Build->Publish Website command asks me for Target Location where I want my web site to be located. I enter c:\Foo.
By default there is a checkbox checked "Allow this precompiled site to be updatable". I will leave this checked. Other options, "Use fixed naming and single page assemblies", and "Enable strong naming on precompiled assemblies" are not checked, and I will leave them like this, because I don't know what they mean.
I click "OK". Visual Studio says "Build started...", then "Publish started...". Visual Studio popped up a box: "Existing files in the destination location will be deleted. Continue?" I clicked "Yes". Visual Studio said "Publish succeeded".
So now c:\Foo directory contains files Default.aspx, PrecompiledApp.config, and a folder named bin. The bin folder contains a file App_Web_k1encpy_.dll .
Now I try to access the URL http://localhost/Foovirt/Default.aspx again. I get an error:
Server Error in '/Foovirt' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this
request. Please review the following specific parse error details and modify your source
file appropriately.
Parser Error Message: Could not load the assembly 'App_Web_k1encpy_'. Make sure that it
is compiled before accessing the page.
Source Error:
Line 1: <%@ page language="C#" autoeventwireup="true" inherits="_Default,
App_Web_k1encpy_" %>
Line 2:
Line 3:
Source File: C:\Foo\Default.aspx Line: 1
I checked the permissions on the folder c:\Foo and its subfolders. I gave full permissions to users MACH\IIS_WPG (where MACH is the name of my machine) and MACH\IUSR_MACH, and made sure they propagated to the subdirectory bin, and to the DLL App_Web_k1encpy_.dll . That didn't help. The error persisted.
When I asked a coworker about this, after some trial and error he opened the Internet Information Services console on my machine, and right-clicked on MACH->Web Sites->Bar->Foovirt subtree, and selected Properties. In the Properties dialog box he clicked on ASP.NET tab. The ASP.NET version field was set to 1.1.xxxx. He set this field to to 2.0.xxxxx, and the application started to work!
Such a simple change, but one that would never occur to me, as a ASP.NET novice. I didn't even know there was an ASP.NET tab in the IIS console. And the error message Windows gives -- "Could not load the assembly 'App_Web_k1encpy_'" is extremely unhelpful. You stare at it and wonder, how can it not find it when it's right there, in the bin folder?
I can only speculate that in my little program I managed to use some .NET Framework classes or methods of some classes that only exist in .NET 2.0. I don't know how else to explain it. And I must say, a Google search for this specific error did not show a solution to my problem. On the other hand, there is much talk about this problem as it crops up in a different context. (Which doesn't encourage me at all. It seems, even if I solve it once, I may run into it again in different circumstances.) |