System.Web.UI.Page.User& # 39;是属性'But用作'类型'
本文关键字:属性 But 类型 用作 UI Web Page User System | 更新日期: 2023-09-27 18:18:53
我知道这是一个新问题,但我需要你的帮助。
我已经运行这个网站很长时间了,当我安装VS2013并重新打开这个解决方案时,我得到了这几个错误。我不能再登录了
错误:
System.Web.UI.Page。User'是一个'属性',但使用起来像'type'
名称"ConnectionClass"在当前上下文中不存在
这是我的Login.cs文件:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
using System.Web.Configuration;
using System.Data.SqlClient;
public partial class 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.Username;
Session["type"] = user.Usertype;
Response.Redirect("~/Home.aspx");
}
else
{
lblError.Text = "Login failed";
}
}
}
和connectionclass。cs
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;
using System.Data.SqlClient;
public class ConnectionClass
{
private static SqlConnection conn;
private static SqlCommand command;
public static ConnectionClass()
{
string connectionString= ConfigurationManager.ConnectionStrings["CISConnectionString"].ToString();
conn = new SqlConnection(connectionString);
command = new SqlCommand("", conn);
}
public static ArrayList GetPOByType(string Customertype)
{
ArrayList list = new ArrayList();
string query = string.Format("SELECT * FROM PO WHERE Customertype LIKE '{0}'", Customertype);
try
{
conn.Open();
command.CommandText = query;
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
int id = reader.GetInt32(0);
string name = reader.GetString(1);
string type = reader.GetString(2);
string image = reader.GetString(3);
string review = reader.GetString(4);
PO PO = new PO(id, name, type, image, review);
list.Add(PO);
}
}
finally
{
conn.Close();
}
return list;
}
public static User LoginUser(string name, string password)
{
//Check if user exists
string query = string.Format("SELECT COUNT(*) FROM Users WHERE Username = '{0}'", name);
command.CommandText = query;
try
{
conn.Open();
int amountOfUsers = (int)command.ExecuteScalar();
if (amountOfUsers == 1)
{
//User exists, check if the passwords match
query = string.Format("SELECT Password FROM Users WHERE Username = '{0}'", name);
命令。CommandText =查询;string dbPassword = command.ExecuteScalar().ToString();
if (dbPassword == password)
{
//Passwords match. Login and password data are known to us.
//Retrieve further user data from the database
query = string.Format("SELECT Email, Usertype FROM Users WHERE Username = '{0}'", name);
command.CommandText = query;
SqlDataReader reader = command.ExecuteReader();
User user = null;
while (reader.Read())
{
string email = reader.GetString(0);
string type = reader.GetString(1);
user = new User(name, password, email, type);
}
return user;
}
else
{
//Passwords do not match
return null;
}
}
else
{
//User does not exist
return null;
}
}
finally
{
conn.Close();
}
}
public static string RegisterUser(User user)
{
//Check if user exists
string query = string.Format("SELECT COUNT(*) FROM Users WHERE Username = '{0}'", user.Username);
command.CommandText = query;
try
{
conn.Open();
int amountOfUsers = (int)command.ExecuteScalar();
if (amountOfUsers < 1)
{
//User does not exist, create a new user
query = string.Format("INSERT INTO users VALUES ('{0}', '{1}', '{2}', '{3}')", user.Username, user.Password,
user.Email, user.Usertype);
command.CommandText = query;
command.ExecuteNonQuery();
return "User registered!";
}
else
{
//User exists
return "A user with this name already exists";
}
}
finally
{
conn.Close();
}
}
}
我真的需要你的帮助。
ConnectionClass
很可能在您试图从(Login.cs)访问它的名称空间中不可用。没有提到ConnectionClass
您需要添加名称空间并确保它们都在相同的名称空间中,或者添加对ConnectionClass所在名称空间的引用(例如使用MySolution.Connectivity
)。