关闭

配置使用EF6.0常见的一些问题及解决方案

发表于:2016-1-26 10:54

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:井传红    来源:51Testing软件测试网采编

  四、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>
  里面的内容可以自己根据需要配置
  总结
  以上是我遇到的众多问题之一,限于篇幅和时间,暂时就记录到这里吧。如果有什么理解错误的地方,还望指正!!!
33/3<123
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号