在MVC中授权问题 - 数据库使用平面文件

时间:2018-04-06 04:30:31

标签: c# asp.net-mvc

我是MVC的新手。我面临着下面的问题。 我在模型中编写了所有逻辑。在Web.config中我提到了文件路径(无连接字符串)。

我正在添加 [HttpPost] [ActionName("Create")] [Authorize] public ActionResult CreateGift(GiftModel gif) { if (Session["UserType"] != null) { if (Session["UserType"].ToString() == "1") return RedirectToAction("Index", "home"); } else { return RedirectToAction("Login", "User"); } string path = System.Configuration.ConfigurationManager.AppSettings["Path"]; if (ModelState.IsValid) { Gift InsertCoupon = new Gift(path); InsertCoupon.InsertGift(gif); return RedirectToAction("GiftList"); } return View(); } 属性。登录后,它将导航到主页。当我导航礼品创建页面再次重定向到登录页面(递归)。

仅供参考:暂时我正在使用会话变量来解决问题。

这是我的代码

<add key="Path" value="D:\"/>

在Web.config中

    public ActionResult Login(LoginModel user)
    {
        string path = System.Configuration.ConfigurationManager.AppSettings["Path"];
        if(ModelState.IsValid)
        { 
        Users LoginUser = new Users(path);
        UserModel uM = new UserModel();
        uM.Password = user.Password;
        uM.User_Email_ID = user.User_Email_ID;
        uM.Name = user.Name;
        string res = LoginUser.LoginUser(uM);
        uM = LoginUser.GetUserFrom_Email(user.User_Email_ID);
        if (res != "")
            ViewBag.Msg = res;
        else
        {
            Session["username"] = uM.Name;
            Session["E_Mail"] = uM.User_Email_ID;
            Session["UserType"] = uM.User_Type;
            if (uM.User_Type == 0)
                return RedirectToAction("AdminHome", "Admin");
            else
                return RedirectToAction("Index", "Home");
        }
        }
        return View();
    }

登录页面

document.getElementById("emotions")

0 个答案:

没有答案