110,561
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Boolean IsAdmin
{
get
{
return _IsAdmin;
}
set
{
OnIsAdminChanging(value);
ReportPropertyChanging("IsAdmin");
_IsAdmin = StructuralObject.SetValidValue(value);
ReportPropertyChanged("IsAdmin");
OnIsAdminChanged();
}
}
private global::System.Boolean _IsAdmin;
partial void OnIsAdminChanging(global::System.Boolean value);
partial void OnIsAdminChanged();
你应该也注意到这段了吧!关键方法就是StructuralObject.SetValidValue,研究一下吧!var v = from s in enity.Users where s.UserID == userID && s.Password == password select s;
if (v.Count() > 0)
{
isAdmin = v.First<DataLayer.User>().IsAdmin;
return true;
}
其中isAdmin = v.First<DataLayer.User>().IsAdmin;给了两个账户一个是True,另外一个是False,
我按F12追踪User, 看到User的类定义:
public partial class User : EntityObject
{
#region Factory Method
/// <summary>
/// Create a new User object.
/// </summary>
/// <param name="password">Initial value of the Password property.</param>
/// <param name="isAdmin">Initial value of the IsAdmin property.</param>
/// <param name="registrationDate">Initial value of the RegistrationDate property.</param>
/// <param name="userID">Initial value of the UserID property.</param>
public static User CreateUser(global::System.String password, global::System.Boolean isAdmin, global::System.DateTime registrationDate, global::System.String userID)
{
User user = new User();
user.Password = password;
user.IsAdmin = isAdmin;
user.RegistrationDate = registrationDate;
user.UserID = userID;
return user;
}
#endregion
#region Primitive Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String Email
{
get
{
return _Email;
}
set
{
OnEmailChanging(value);
ReportPropertyChanging("Email");
_Email = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("Email");
OnEmailChanged();
}
}
private global::System.String _Email;
partial void OnEmailChanging(global::System.String value);
partial void OnEmailChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String Password
{
get
{
return _Password;
}
set
{
OnPasswordChanging(value);
ReportPropertyChanging("Password");
_Password = StructuralObject.SetValidValue(value, false);
ReportPropertyChanged("Password");
OnPasswordChanged();
}
}
private global::System.String _Password;
partial void OnPasswordChanging(global::System.String value);
partial void OnPasswordChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Boolean IsAdmin
{
get
{
return _IsAdmin;
}
set
{
OnIsAdminChanging(value);
ReportPropertyChanging("IsAdmin");
_IsAdmin = StructuralObject.SetValidValue(value);
ReportPropertyChanged("IsAdmin");
OnIsAdminChanged();
}
}
private global::System.Boolean _IsAdmin;
partial void OnIsAdminChanging(global::System.Boolean value);
partial void OnIsAdminChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.DateTime RegistrationDate
{
get
{
return _RegistrationDate;
}
set
{
OnRegistrationDateChanging(value);
ReportPropertyChanging("RegistrationDate");
_RegistrationDate = StructuralObject.SetValidValue(value);
ReportPropertyChanged("RegistrationDate");
OnRegistrationDateChanged();
}
}
private global::System.DateTime _RegistrationDate;
partial void OnRegistrationDateChanging(global::System.DateTime value);
partial void OnRegistrationDateChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String Firstname
{
get
{
return _Firstname;
}
set
{
OnFirstnameChanging(value);
ReportPropertyChanging("Firstname");
_Firstname = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("Firstname");
OnFirstnameChanged();
}
}
private global::System.String _Firstname;
partial void OnFirstnameChanging(global::System.String value);
partial void OnFirstnameChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String Lastname
{
get
{
return _Lastname;
}
set
{
OnLastnameChanging(value);
ReportPropertyChanging("Lastname");
_Lastname = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("Lastname");
OnLastnameChanged();
}
}
private global::System.String _Lastname;
partial void OnLastnameChanging(global::System.String value);
partial void OnLastnameChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String UserID
{
get
{
return _UserID;
}
set
{
if (_UserID != value)
{
OnUserIDChanging(value);
ReportPropertyChanging("UserID");
_UserID = StructuralObject.SetValidValue(value, false);
ReportPropertyChanged("UserID");
OnUserIDChanged();
}
}
}
private global::System.String _UserID;
partial void OnUserIDChanging(global::System.String value);
partial void OnUserIDChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String HLinfo
{
get
{
return _HLinfo;
}
set
{
OnHLinfoChanging(value);
ReportPropertyChanging("HLinfo");
_HLinfo = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("HLinfo");
OnHLinfoChanged();
}
}
private global::System.String _HLinfo;
partial void OnHLinfoChanging(global::System.String value);
partial void OnHLinfoChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public Nullable<global::System.Boolean> NoDebt
{
get
{
return _NoDebt;
}
set
{
OnNoDebtChanging(value);
ReportPropertyChanging("NoDebt");
_NoDebt = StructuralObject.SetValidValue(value);
ReportPropertyChanged("NoDebt");
OnNoDebtChanged();
}
}
private Nullable<global::System.Boolean> _NoDebt = false;
partial void OnNoDebtChanging(Nullable<global::System.Boolean> value);
partial void OnNoDebtChanged();
#endregion
}
就是这个类的引用让这两个账户让变量isAdmin有了不同的值。
大神们,你们看这个类哪里出了问题呢?
对了,我在web.config中看到对用户进入网页的权限进行了规定,我把所有原来正确的管理员账号的allow的部分都拷贝给了第二个账户,但是仍然不管用。一个朋友说要进入网页上的asp.net administrative tool 进行设定。对么?
public static int CalcWeightChange(string userId)
{
MOREntities entity = new MOREntities();
double weight1 = 0.0;
double weight2 = 0.0;
double weightChange = 0.0;
var j = from i in entity.WeightReports where i.UserId == userId orderby i.ReportedDate select i;
List<WeightReport> reports = j.ToList();
if (reports.Count() > 1)
{
weight2 = reports[reports.Count() - 2].Weight;
weight1 = reports[reports.Count() - 1].Weight;
weightChange = weight1 - weight2;
}
return (int) Math.Round(weightChange);
}
public List<string[]> GetUsers()
{
MOREntities entity = new MOREntities();
var s = from v in entity.Users where v.IsAdmin == false orderby v.UserID select v;
string[] userData = new string[2];
List<string[]> userList = new List<string[]>();
foreach (DataLayer.User user in s)
{
userData = new string[2];
userData[0] = user.UserID;
userData[1] = CalcWeightChange(user.UserID).ToString();
userList.Add(userData);
}
return userList;
}
public static void DeleteUser(string userID)
{
MOREntities entity = new MOREntities();
DataLayer.User user = (from s in entity.Users where s.UserID == userID select s).First<DataLayer.User>();
entity.Users.DeleteObject(user);
var report = (from v in entity.WeightReports where v.UserId == userID select v);
if (report.Count() > 0)
{
entity.WeightReports.DeleteObject(report.First<WeightReport>());
}
var report1 = (from j in entity.WaistReports where j.UserId == userID select j);
if (report1.Count() > 0)
{
entity.WaistReports.DeleteObject(report1.First());
}
var attribute = (from a in entity.UserAttributes where a.UserId == userID select a);
if (attribute.Count() > 0)
{
entity.UserAttributes.DeleteObject(attribute.First());
}
entity.SaveChanges();
}
public static DateTime? GetRegistrationDate(string userID)
{
MOREntities enity = new MOREntities();
var name = from s in enity.Users where s.UserID == userID select s;
if (name.Count() > 0)
{
return name.ToList<DataLayer.User>()[0].RegistrationDate;
}
else
{
return null;
}
}
public static DataLayer.User GetUserObject(string userID)
{
MOREntities entity = new MOREntities();
var name = from s in entity.Users where s.UserID == userID select s;
if (name.Count() > 0)
{
return name.ToList<DataLayer.User>()[0];
}
else
{
return null;
}
}
public static double GetWaist(string userId)
{
MOREntities entity = new MOREntities();
var s = from v in entity.UserAttributes where v.UserId == userId select v;
if (s.Count() > 0)
{
return s.First<UserAttribute>().Waist;
}
else
{
return 0.0;
}
}
public static double GetLength(string userId)
{
MOREntities entity = new MOREntities();
var s = from v in entity.UserAttributes where v.UserId == userId select v;
if (s.Count() > 0)
{
return s.First<UserAttribute>().Length;
}
else
{
return 0.0;
}
}
public static double GetStartWeight(string userId)
{
MOREntities entity = new MOREntities();
var s = from v in entity.UserAttributes where v.UserId == userId select v;
if (s.Count() > 0)
{
return s.First<UserAttribute>().StartWeight;
}
else
{
return 0.0;
}
}
public static double GetWantedWeight(string userId)
{
MOREntities entity = new MOREntities();
var s = from v in entity.UserAttributes where v.UserId == userId select v;
if (s.Count() > 0)
{
return s.First<UserAttribute>().WantedWeight;
}
else
{
return 0.0;
}
}
public static bool UserExists(string userId)
{
MOREntities entity = new MOREntities();
var exist = from a in entity.Users where a.UserID == userId select a;
return (exist.Count() > 0);
}