ASP.NET App_Code 目录中的程序集引用
我在为 asp:ListView 控件获取自定义 ObjectDataSource 时遇到问题。我在 Web 应用程序的 App_Code 目录中有 DataSource 的类(根据 asp:ListView 控件的要求)。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Web;
using System.DirectoryServices;
[DataObject]
public class UsersDAL
{
[DataObjectMethod(DataObjectMethodType.Select)]
public List<User> LoadAll(int startIndex, int maxRows, string sortedBy)
{
List<User> users = new List<User>();
DirectoryEntry entry;
return users;
}
}
一旦我添加using System.DirectoryServices;
,页面就会崩溃并显示以下消息:编译器错误消息:CS0234:命名空间“System”中不存在类型或命名空间名称“DirectoryServices”(是否缺少程序集引用?)
如果不使用 System.DirectoryServices,页面加载不会出现问题。
引用就在那里,它在 App_Code 目录之外的类中工作。
I have trouble getting a custom ObjectDataSource for an asp:ListView control to work. I have the class for the DataSource in the App_Code directory of the web application (as required by the asp:ListView control).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Web;
using System.DirectoryServices;
[DataObject]
public class UsersDAL
{
[DataObjectMethod(DataObjectMethodType.Select)]
public List<User> LoadAll(int startIndex, int maxRows, string sortedBy)
{
List<User> users = new List<User>();
DirectoryEntry entry;
return users;
}
}
As soon as I add using System.DirectoryServices;
the page crashes with this message:Compiler Error Message: CS0234: The type or namespace name 'DirectoryServices' does not exist in the namespace 'System' (are you missing an assembly reference?)
Without the usage of System.DirectoryServices the page loads without problems.
The reference is there, it is working in classes outside the App_Code
directory.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑 Web 应用程序项目和网站之间存在混淆。你有哪一个?
您的 web.config 中是否有对 System.DirectoryServices 的引用?可能不会。这就是它不起作用的原因。
如果您有 Web 应用程序项目,则无需使用 App_Code。这是不必要的,而且可能有害。举个例子,你的麻烦就在这里。
I suspect a mix-up between Web Application Project and a Web Site. Which do you have?
Do you have a reference to System.DirectoryServices in your web.config? Probably not. And this is why it's not working.
If you have a Web Application Project, dispense with App_Code. It is unnecessary, and potentially harmful. Case in point, your trouble here.