I am currently trying to cleanup a bit of a corporate website that I inherited here. I managed to clean up most of the errors in the website but something is still up here.
我目前正在尝试清理我在这里继承的一些公司网站。我设法清理了网站上的大部分错误,但仍有一些问题在这里。
I have one masterpage that have this code :
我有一个包含此代码的母版页:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class MasterPage : System.Web.UI.MasterPage {
public lists m_listsClass = new lists();
(no it's not a typo the S in lists).
(不,这不是列表中S的错字)。
Now in App_code I have one class lists.cs
现在在App_code中我有一个类lists.cs
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
/// <summary>
/// Summary description for lists
/// </summary>
public class lists
{
public lists()
{
When I try to build the website in visual studio 2008 I have this error :
当我尝试在visual studio 2008中构建网站时,我有这样的错误:
Error 3 The type or namespace name 'lists' could not be found (are you missing a using directive or an assembly reference?) C:\Users\egirard\Documents\Visual Studio 2008\Projects\iFuzioncorp\iFuzioncorp\Masters\MasterPage.master.cs 23 12 iFuzioncorp
Am I missing something ?
我错过了什么吗?
Also I saw some strange behaviour on the server. Apparently according to IIS7 it is compiling using .net 2.0 (the pool is configured with .net 2) but there are some "using
" statements that include Linq ... how is it possible to compile the page if Linq is not part of the .net 2 itself ?
我也在服务器上看到了一些奇怪的行为。显然根据IIS7,它正在使用.net 2.0进行编译(池配置了.net 2)但是有一些“使用”语句包含Linq ...如果Linq不是其中的一部分,如何编译页面是可能的.net 2本身?
Just edited with news details on the code itself. No namespace at all everywhere.
刚编辑了代码本身的新闻详细信息。到处都没有命名空间。
8 个解决方案
#1
Hi There – i had a similar problem; all my namespaces and inheritance was in place. Then i then noticed that the class file’s build action was set to “Content” not “Compile” (in the properties window.
你好 - 我有类似的问题;我的所有命名空间和继承都已到位。然后我注意到类文件的构建操作设置为“内容”而不是“编译”(在属性窗口中)。
#2
For whatever worth might there be for an answer (possibly not the right one) after many months, i think i should contribute this:
对于任何值得在几个月后得到答案(可能不是正确的答案),我想我应该做出贡献:
There is a case that this happens, when you place a web site inside another (ie in a subfolder). In that case, the only App_Code folder that is legitimate is the App_code folder of the outer web site. That is, the App_Code folder right under the root of the master web site.
当您将网站放在另一个网站(即子文件夹中)时,会发生这种情况。在这种情况下,唯一合法的App_Code文件夹是外部网站的App_code文件夹。也就是说,主网站根目录下的App_Code文件夹。
Maybe (say maybe) there should be no need to transform your web site to a web application, if you place the class file inside the App_code folder of the ROOT web site.
如果将类文件放在ROOT网站的App_code文件夹中,也许(比如说)可能不需要将您的网站转换为Web应用程序。
#3
include the namespace under which lists calss is defined
包括定义列表calss的命名空间
or
define both the master page and lists class under the same namespace
在同一名称空间下定义母版页和列表类
#4
Finally I understood quite lately that it was a website and not a web application I had to question the guys here to get it... So it's quite normal all the error I had. I haven't had the occasion to convert it first.
最后我最近才明白这是一个网站,而不是一个网络应用程序,我不得不质疑这里的人来获取它......所以我所有错误都很正常。我没有机会先转换它。
#5
Make sure that in your masterpage, you have an #include statement for the namespace that the lists class is a part of (if they're in seperate namespaces, the masterpage isn't going to automatically pick up on it).
确保在您的母版页中,您有一个列表类所属的命名空间的#include语句(如果它们位于单独的命名空间中,则母版页不会自动获取它)。
As for the strange server side behavior, .NET 2.0, 3.0, and 3.5 all run inside of .NET 2.0 app pools in IIS. It looks strange at first, but you get used to it. Here's a link with a little more in-depth explination:
至于奇怪的服务器端行为,.NET 2.0,3.0和3.5都在IIS中的.NET 2.0应用程序池中运行。起初看起来很奇怪,但你已经习惯了。这是一个更深入探索的链接:
The Way I See It: Where is ASP.NET 3.5 on IIS?
我看到它的方式:IIS上的ASP.NET 3.5在哪里?
#6
In order to use a type, you must reference the assembly which defines it and include the appropriate namespace.
要使用类型,必须引用定义它的程序集并包含相应的名称空间。
Using only includes namespaces, if you don't use any types from said namespaces it has no effect.
仅使用包含名称空间,如果不使用所述名称空间中的任何类型,则它不起作用。
#7
is lists.cs wrapped in a namespace? if it is the case then you need to add the namespace (yournamespace.lists) or include it in masterpage. Check Also if your MasterPage is in a Namespace
是包含在命名空间中的lists.cs吗?如果是这种情况,那么您需要添加命名空间(yournamespace.lists)或将其包含在母版页中。还检查您的MasterPage是否在命名空间中
#8
-
Modify the Build Action of the App_Code Class to Compile.
修改App_Code类的Build Action以编译。
-
Clean and Build the Project
清理和建造项目
This worked for me.
这对我有用。
#1
Hi There – i had a similar problem; all my namespaces and inheritance was in place. Then i then noticed that the class file’s build action was set to “Content” not “Compile” (in the properties window.
你好 - 我有类似的问题;我的所有命名空间和继承都已到位。然后我注意到类文件的构建操作设置为“内容”而不是“编译”(在属性窗口中)。
#2
For whatever worth might there be for an answer (possibly not the right one) after many months, i think i should contribute this:
对于任何值得在几个月后得到答案(可能不是正确的答案),我想我应该做出贡献:
There is a case that this happens, when you place a web site inside another (ie in a subfolder). In that case, the only App_Code folder that is legitimate is the App_code folder of the outer web site. That is, the App_Code folder right under the root of the master web site.
当您将网站放在另一个网站(即子文件夹中)时,会发生这种情况。在这种情况下,唯一合法的App_Code文件夹是外部网站的App_code文件夹。也就是说,主网站根目录下的App_Code文件夹。
Maybe (say maybe) there should be no need to transform your web site to a web application, if you place the class file inside the App_code folder of the ROOT web site.
如果将类文件放在ROOT网站的App_code文件夹中,也许(比如说)可能不需要将您的网站转换为Web应用程序。
#3
include the namespace under which lists calss is defined
包括定义列表calss的命名空间
or
define both the master page and lists class under the same namespace
在同一名称空间下定义母版页和列表类
#4
Finally I understood quite lately that it was a website and not a web application I had to question the guys here to get it... So it's quite normal all the error I had. I haven't had the occasion to convert it first.
最后我最近才明白这是一个网站,而不是一个网络应用程序,我不得不质疑这里的人来获取它......所以我所有错误都很正常。我没有机会先转换它。
#5
Make sure that in your masterpage, you have an #include statement for the namespace that the lists class is a part of (if they're in seperate namespaces, the masterpage isn't going to automatically pick up on it).
确保在您的母版页中,您有一个列表类所属的命名空间的#include语句(如果它们位于单独的命名空间中,则母版页不会自动获取它)。
As for the strange server side behavior, .NET 2.0, 3.0, and 3.5 all run inside of .NET 2.0 app pools in IIS. It looks strange at first, but you get used to it. Here's a link with a little more in-depth explination:
至于奇怪的服务器端行为,.NET 2.0,3.0和3.5都在IIS中的.NET 2.0应用程序池中运行。起初看起来很奇怪,但你已经习惯了。这是一个更深入探索的链接:
The Way I See It: Where is ASP.NET 3.5 on IIS?
我看到它的方式:IIS上的ASP.NET 3.5在哪里?
#6
In order to use a type, you must reference the assembly which defines it and include the appropriate namespace.
要使用类型,必须引用定义它的程序集并包含相应的名称空间。
Using only includes namespaces, if you don't use any types from said namespaces it has no effect.
仅使用包含名称空间,如果不使用所述名称空间中的任何类型,则它不起作用。
#7
is lists.cs wrapped in a namespace? if it is the case then you need to add the namespace (yournamespace.lists) or include it in masterpage. Check Also if your MasterPage is in a Namespace
是包含在命名空间中的lists.cs吗?如果是这种情况,那么您需要添加命名空间(yournamespace.lists)或将其包含在母版页中。还检查您的MasterPage是否在命名空间中
#8
-
Modify the Build Action of the App_Code Class to Compile.
修改App_Code类的Build Action以编译。
-
Clean and Build the Project
清理和建造项目
This worked for me.
这对我有用。