[英]asp.net login page inherit attribute c#
i keep getting this following error: 我不断收到以下错误:
ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (eg Page or UserControl). ASPNET:确保此代码文件中定义的类与'inherits'属性匹配,并且确保它扩展了正确的基类(例如Page或UserControl)。
it tells me the error is with the following: Login.aspx.cs Line: 1 它显示出以下错误:Login.aspx.cs行:1
Line 1: using System;
Line 2: using Entities;
Line 3: namespace Pages.Account
here is the code for my login.aspx file 这是我的login.aspx文件的代码
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Pages.Account.Pages_Account_Login" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table>
<tr>
<td><b>Login: </b></td>
<td>
<asp:TextBox ID="txtLogin" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="*" ControlToValidate="txtLogin"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td><b>Password: </b></td>
<td>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="*" ControlToValidate="txtPassword"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnLogin" runat="server" Text="Login"
onclick="btnLogin_Click" /><br/>
<asp:Label ID="lblError" runat="server" Text=""></asp:Label>
<br />
<asp:LinkButton ID="LinkButton2" runat="server"
PostBackUrl="~/Pages/Account/Registration.aspx">Register</asp:LinkButton>
</td>
</tr>
</table>
</asp:Content>
here is the code for my login.aspx.cs file: 这是我的login.aspx.cs文件的代码:
using System;
using Entities;
namespace Pages.Account
{
public partial class Pages_Account_Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
User user = ConnectionClass.LoginUser(txtLogin.Text, txtPassword.Text);
if(user != null)
{
//Store login variables in session
Session["login"] = user.Name;
Session["type"] = user.Type;
Response.Redirect("~/Pages/Home.aspx");
}
else
{
lblError.Text = "Login failed";
}
}
}
}
any help would be greatly appreciated. 任何帮助将不胜感激。
Thank you. 谢谢。
I see the problem in your code; 我在您的代码中看到了问题; Inherits and Code Behind Class are different. 继承和代码隐藏类是不同的。
Ideally, class name should be - 理想情况下,类名应为-
public partial class Login : System.Web.UI.Page
{
...
}
and Inherits should be 和继承应该是
<%@ Page ... CodeFile="Login.aspx.cs" Inherits="Pages.Account.Login" %>
For Web Application Project, it should be CodeBehind . 对于Web应用程序项目,它应该是CodeBehind 。
<%@ Page ... CodeBehind="Login.aspx.cs" Inherits="Pages.Account.Login" %>
I don't see anything wrong on the surface. 我看不到表面有任何问题。
When I hit the voodoo asp.net errors. 当我遇到voodoo asp.net错误时。
I do the following: 我执行以下操作:
Rename MyProblemPage.aspx to MyProblemPageOLD.aspx. 将MyProblemPage.aspx重命名为MyProblemPageOLD.aspx。
Create a new MyProblemPage.aspx. 创建一个新的MyProblemPage.aspx。
REMOVE FROM PROJECT (do not delete) MyProblemPageOLD.aspx 从项目中删除(请勿删除)MyProblemPageOLD.aspx
Compile. 编译。 Should be no errors. 应该没有错误。
Move the code from aspx and .cs from MyProblemPageOLD.aspx, MyProblemPageOLD.aspx.cs 从MyProblemPageOLD.aspx,MyProblemPageOLD.aspx.cs中的aspx和.cs中移动代码
Compile. 编译。 It should work. 它应该工作。
If it compiles now, delete MyProblemPageOLD*.* 如果现在可以编译,请删除MyProblemPageOLD *。*
I know its not a fix, but it will get you moving again. 我知道这不是解决办法,但是它将带您再次前进。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.