【发布时间】:2013-06-12 11:15:54
【问题描述】:
我正在使用公共 LoginContext 类来管理我的网络应用程序中的用户登录。
不幸的是,即使我公开声明了 LoginContext 类,我在 Login.aspx.cs 的部分类 Login 似乎无法访问它。
我的代码如下:
// ~/App_Code/LoginContext.cs
namespace stman
{
public class LoginContext
{
}
}
// ~/Login.aspx.cs
namespace stman
{
public partial class Login : System.Web.UI.Page
{
protected void btnLogin_Click(object sender, EventArgs e)
{
LoginContext log = new LoginContext(); // error is here
}
}
}
在我实例化 LoginContext 的那一行出现的错误如下:
找不到类型或命名空间名称“LoginContext”(您是否缺少 using 指令或程序集引用?)
当我尝试为 LoginContext 生成一个新类时,它会进入 Web 应用程序的根文件夹,在那里它无法再访问我在 LoginContext 中需要的公共数据库类。
我不知道是什么导致了所有这些问题,但根据我过去 18 个月的专业知识,它们现在不应该存在......
有人可以帮忙清理这里的东西吗?具体我想知道:
- 我做错了什么
- 为什么会出错
- 谁能解决?
提前致谢!
编辑
我看了看,似乎 ~/App_Code/Database.cs 中的 Database 类或 ~/App_Code/LoginContext.cs 中的 LoginContext 类都无法访问页面 - 或网站中的任何页面。
【问题讨论】:
-
尝试添加 LoginContext 类的命名空间
-
如果检查 LoginContext.cs 属性,它是否标记为 BuildAction = Compile ?
-
@Nag 没有帮助。 LoginContext 似乎不是命名空间的一部分,尽管我可以清楚地看到它是
-
@OndrejSvejdar BuildAction for LoginContext.cs 是
Content -
切换到编译。
标签: c# asp.net class inheritance