【问题标题】:System.Web.UI.Page.User' is a 'property' but is used like a 'type'System.Web.UI.Page.User' 是一个“属性”,但用作“类型”
【发布时间】:2014-08-20 11:14:24
【问题描述】:

我知道这是一个新手问题,但我需要你的帮助。

我已经运行这个网站很长时间了,当我安装 VS2013 并重新打开这个解决方案时,我遇到了这几个错误。而且我再也无法登录了。

错误:

'System.Web.UI.Page.User' 是一个“属性”,但用作“类型”

当前上下文中不存在名称“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);

command.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();
}
}


}

我真的需要你的帮助。

【问题讨论】:

  • 你在哪一行得到错误?
  • 请重新格式化您的代码,使其更具可读性。

标签: c# properties


【解决方案1】:

ConnectionClass 在您尝试从 (Login.cs) 访问的命名空间中很可能不可用。没有提到ConnectionClass

您需要添加命名空间并确保它们都在同一个或添加对 ConnectionClass 所在命名空间的引用(例如,使用 MySolution.Connectivity )。

【讨论】:

    猜你喜欢
    • 2015-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-22
    • 2016-10-17
    • 1970-01-01
    • 2022-12-19
    • 1970-01-01
    相关资源
    最近更新 更多