Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我无法使用asp.net标识对登录asp.net mvc5的用户进行身份验证_C#_Security_Asp.net Mvc 4_Authentication_Asp.net Identity - Fatal编程技术网

C# 我无法使用asp.net标识对登录asp.net mvc5的用户进行身份验证

C# 我无法使用asp.net标识对登录asp.net mvc5的用户进行身份验证,c#,security,asp.net-mvc-4,authentication,asp.net-identity,C#,Security,Asp.net Mvc 4,Authentication,Asp.net Identity,当我将[authorize]标记放在将我重定向到用户仪表板的操作顶部时,我正在使用asp.net标识,此时我被重定向回登录页面。这对我来说意味着我的asp.net标识中缺少了一些内容,因为我无法授权任何用户访问仪表板,除非我删除授权标记 用于登录的我的家庭控制器 [HttpPost] [ValidateAntiForgeryToken] public ActionResult Login(UserProfile objUser) {

当我将[authorize]标记放在将我重定向到用户仪表板的操作顶部时,我正在使用asp.net标识,此时我被重定向回登录页面。这对我来说意味着我的asp.net标识中缺少了一些内容,因为我无法授权任何用户访问仪表板,除非我删除授权标记

用于登录的我的家庭控制器

 [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Login(UserProfile objUser)
        {
            if (ModelState.IsValid /*&& WebSecurity.Login(objUser.UserName.ToString(), objUser.Password )*/)
            {
                using (MarketingDBEntitiesModel db = new MarketingDBEntitiesModel()) 
                {
                    var obj = db.UserProfiles.Where(a => a.UserName.Equals(objUser.UserName) && a.Password.Equals(objUser.Password)).FirstOrDefault();

                    if (obj != null)
                    {
                        Session["UserID"] = obj.UserId.ToString();
                        Session["UserName"] = obj.UserName.ToString();
                        ConfigurationManager.AppSettings["CurrentUserId"] = Session["UserID"].ToString();                     
                        ConfigurationManager.AppSettings["UserName"] = objUser.UserName;
                        //await SignIn(obj.UserId.ToString(), false);
                        return RedirectToAction("UserDashBoard");
                    }
                }
            }
            return View(objUser);
        }

        [Authorize]
        public ActionResult UserDashBoard()
        {
            if (Session["UserID"] != null)
            {
                return View();
            }
            else
            {
                return RedirectToAction("Login");
            }
        }
我的网络配置

<authentication mode="Forms">
      <forms loginUrl="~/Home/Login" timeout="2880" />
    </authentication>


当然,这会失败。您的代码没有授权用户,您只是为会话设置值并将其保存到web.config


请看这篇文章。

用户主页是什么:“~/home/Login”?对于授权用户,它应该重定向到主页/用户仪表板。配置设置必须位于用户可以访问的位置。你真的想在配置文件中有使用列表吗?我想出于测试目的,可以将其放在那里,但用户需要对文件夹/文件具有读取权限;您必须将用户放入文件中进行测试。