四、Dept部门表中必须有主键
五、调用的时候
db.a_Emp.Include("Dept").Where(l => l.Dept.name.Contains(name)||string.IsNullOrEmpty(name)).ToList()
其中a_Emp是员工类的实体对象,在baseContext里面的 public DbSet<Employee>a_Emp { get; set; }
Dept.name是可以直接点出来的了
HttpContext.User.Identity.IsAuthenticated一直为false
使用mvc时会用到权限控制,并且存cookie,然后一般会出现下面的一段代码
protected override void OnActionExecuting(ActionExecutingContext filterContext) { var request = filterContext.HttpContext.Request; var response = filterContext.HttpContext.Response; currentUser = new AdminUser(); if (filterContext.HttpContext.User.Identity.IsAuthenticated) { long.TryParse(System.Web.HttpContext.Current.User.Identity.Name, out userid); if (userid > 0) { currentUser = AdminUserDAL.getEntryById<AdminUser, long>(userid); currentUser.allprivileges = AdminUserDAL.getUserPrivilegeAll(-1, userid); myPermissionList = currentUser.allprivileges; } } else //返回登录页 { response.Redirect("/Acount/Login"); } |
一直为false的时候就会出现始终跳到登录页,就算调试也找不到为什么会这样
解决方案
在webconfig文件的system.web节点下面加入节点就行了
<authentication mode="Forms">
<forms loginUrl="~/Home/Login" name="paochi.com" timeout="300" protection="All" path="/" requireSSL="false" slidingExpiration="false" enableCrossAppRedirects="false" cookieless="UseCookies" />
</authentication>
里面的内容可以自己根据需要配置
总结
以上是我遇到的众多问题之一,限于篇幅和时间,暂时就记录到这里吧。如果有什么理解错误的地方,还望指正!!!