在我自己的电脑上运行时,出现了两个错误:
1. 
Error 2 Unexpected error creating debug information file 'C:\Users\Erik Zhou\Documents\Visual Studio 2010\Projects\MOR1\License\obj\Debug\License.PDB' -- 'C:\Users\Erik Zhou\Documents\Visual Studio 2010\Projects\MOR1\License\obj\Debug\License.pdb: Access is denied.
'2. 
Error 4 Could not write lines to file "obj\Debug\License.csproj.FileListAbsolute.txt". Access to the path 'C:\Users\Erik Zhou\Documents\Visual Studio 2010\Projects\MOR1\License\obj\Debug\License.csproj.FileListAbsolute.txt' is denied. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets 3658这两个错误啥意思啊?

解决方案 »

  1.   

    很有可能你的程序不是简单的就读了user那一张表,是否还有权限(绑定菜单功能之类的)。然后程序中加载时(sql关联查询),并没有查到这个用户(sql关联查询时过滤了你添加的这个账号)。
      

  2.   

    很靠谱的想法。这个网站的作者很喜欢关联查询。因为我对C#和ms sql server的知识基本为零,能否请你指点这个问题:
    我用的是Visual Studio 2010,此刻在我面前的vs 2010界面有四部分,如下图。尤其特别注意,左边是所有文件以及代码的树形结构的窗口。原作者喜欢把关于database的部分放在一起,请大神们看看,我应该查询那个部分?以及大概什么文件呢?小弟我搞php+mysql的,找了半天,也没有找到貌似链接sql server语句?请大神们谅解,我这段时间专门来擦别人的屁股,自己也不懂C#,只能一点点问清楚了,还请大神们讲讲有用的细节,我能够顺藤摸瓜的。
    谢谢。
      

  3.   

    从你截的图上的代码来看,用的是Entity Framework(EF)操作数据库的,是微软C#的ORM(类似于java中的hibernate)。你可以把光标放到MOREntities上面,按F12定位到MOREntities的定义部分。
    http://blog.csdn.net/chinacsharper/article/details/9368855
      

  4.   

    对了,我发现了一个UserManager.cs的文件,里面很像搜索user并判断的,上代码,还请大神们指点:
    [code=csharp]
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.Objects;
    using System.Data.Objects.SqlClient;
    using DataLayer;
    namespace Users
    {
        public class UserManager
        {
            public static bool Authenticate(string userID, string password, out bool isAdmin)
            {            MOREntities enity = new MOREntities();            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;            }
                else
                {
                    isAdmin = false;
                    return false;
                }        }        private static string[] SetDefaultValues(int year, int month, string[] arr)
            {            int days = DateTime.DaysInMonth(year,month);            for (int i = 1; i <= days; i++)
                {
                    arr[i] = "-";
                }            return arr;        }        public static string GetHLinfo(string userId)
            {
                DataLayer.User user = GetUserObject(userId);            if (user != null)
                {
                    if (user.HLinfo != null)
                    { return user.HLinfo; }
                    else
                    { return "No information available at present."; }
                }
                else
                {
                    return string.Empty;
                }        }
            public static void EditHLinfo(string userID, string HLinfo)
            {
                MOREntities entity = new MOREntities();            var user = from a in entity.Users where a.UserID == userID select a;            if (user.Count() > 0)
                {
                    user.First().HLinfo = HLinfo;
                    entity.SaveChanges();            }        }
                    public static List<string[]> GetLoginHistory(int month, int year)
            {
                MOREntities entity = new MOREntities();            const int numCols = 32;            string user = "";            string[] value = null;
        
                List<string[]> values = new List<string[]>();            dynamic history = (from a in entity.LoginHistories group a by new { UserId = a.UserId, LoginTime = EntityFunctions.TruncateTime(a.LoginTime) } into grp where grp.Key.LoginTime.Value.Month == month && grp.Key.LoginTime.Value.Year == year
                                   orderby grp.Key.UserId select new { UserId = grp.Key.UserId, Date = EntityFunctions.TruncateTime(grp.Key.LoginTime), LoginCount = grp.Count() }).ToArray();            int i = 0;            while (i < history.Length)
                {
                    if (i == 0)
                    {
                        value = new string[numCols];                    value = SetDefaultValues(year, month, value);
                        value[0] = history[i].UserId;
                        value[history[i].Date.Day] = history[i].LoginCount.ToString();
                    }
                    else
                    {
                        if (history[i].UserId == history[i - 1].UserId)
                        {
                            value[history[i].Date.Day] = history[i].LoginCount.ToString();
                        }
                        else
                        {
                            values.Add(value);
                            value = new string[numCols];                        SetDefaultValues(year, month, value);                        value[0] = history[i].UserId;
                            user = history[i].UserId;
                            value[history[i].Date.Day] = history[i].LoginCount.ToString();
                        }
                    }                i++;
                }            values.Add(value);            return values;        }        public static void ReportLogin(string userId, DateTime time)
            {
                MOREntities entity = new MOREntities();            LoginHistory login = new LoginHistory();            login.UserId = userId;
                login.LoginTime = time;            entity.LoginHistories.AddObject(login);            entity.SaveChanges();        }        public static void ChangePassword(string userID, string password)
            {
                MOREntities entity = new MOREntities();            var user = from a in entity.Users where a.UserID == userID select a;            if (user.Count() > 0)
                {
                    user.First().Password = password;
                    entity.SaveChanges();            }        }        public static string GetPassword(string userId)
            {
                DataLayer.User user = GetUserObject(userId);            if (user != null)
                {
                    return user.Password;
                }            return "";        }        public static void EditUser(string userId, int weight, int waist, int length, int wantedWeight)
            {
                MOREntities entity = new MOREntities();            var user = from v in entity.UserAttributes where v.UserId == userId select v;            if (user.Count() > 0)
                {
                    user.First().Waist = waist;
                    user.First().StartWeight = weight;
                    user.First().WantedWeight = wantedWeight;
                    user.First().Length = length;
                    
                    entity.SaveChanges();
                }
                else
                {
                    UserAttribute attribute = new UserAttribute();                attribute.Length = length;
                    attribute.UserId = userId;
                    attribute.Waist = waist;
                    attribute.WantedWeight = wantedWeight;
                    attribute.StartWeight = weight;
                    entity.UserAttributes.AddObject(attribute);
                    entity.SaveChanges();
                }        }
      

  5.   

    第二部分代码是:
           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);        }
      

  6.   

    同意楼上的观点,你在Login的方法主体内调试下,或者查询下所有的User,也可以Console到输出窗口,首先看看数据是否存在,其次看看你添加的数据和其他正常的数据有什么不一样的地方
      

  7.   

    看一下user表里的是否有IsAdmin及对应的值。
      

  8.   

    感谢楼上大神们的建议,目前情况是这样的:
    我用一个管理员帐号和我加入数据库的账号(我设定了数据库表格里一切看起来是管理员的值,表中字段IsAdmin设定为True)登录网站,一步一步查询,发现这个语句给了不同的值:
    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 进行设定。对么?
      

  9.   

    晕死,我在哪里乱设一通,现在什么账户都进不去系统了。出错信息是:
    Server Error in '/' Application.Access is denied.Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL. Error message 401.2.: Unauthorized: Logon failed due to server configuration.  Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server.  Contact the Web server's administrator for additional assistance.Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1016
      

  10.   

    一个帐号和密码,你竟然得到了两个人的信息,说明你的帐号和密码信息重复了,如果你使用First得到的第一条数据估计就是那个IsAdmin为false的那条数据
      

  11.   

            /// <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,研究一下吧!