2017-12-08 4 views
0

私はカスタムログインプロセスを作成しようとしています。このためにセッションを使用したいのですが、asp.net MVCは私がセッションを使用する方法を教えてください。ユーザーからログアウトしたかどうかをチェックするだけで、ログインせずにダッシュボードにアクセスできるようになります。前もって感謝します。どのようにセッションを使用し、セッションに値を格納し、ログイン用sysytemを使用する

Session["user"] = profile.userName; 
       var admin = db.userProfiles.Where(x => x.userName == user.userName && x.password == user.password && x.admin==1).FirstOrDefault(); 
       if(admin==null) 
       { 
        if (Session["user"] != null) 
        { 
         ViewBag.userName = user.userName; 
         return View(); 
        } 
        else 
        { 
         return RedirectToAction("login"); 
        } 

       } 
       else 
       { 

        if (Session["user"] != null) 
        { 
         return RedirectToAction("index"); 
        } 
        else 
        { 
         return RedirectToAction("login"); 
        } 

答えて

0

あなたは車輪を再発明しています。組み込みのIDと認証スキームの使用を検討しましたか?

承認 https://docs.microsoft.com/en-us/aspnet/core/security/authorization/secure-data

ASP.NETアイデンティティを持つシンプルなToDoのアプリケーションを構築し、ToDoes https://blogs.msdn.microsoft.com/webdev/2013/10/20/building-a-simple-todo-application-with-asp-net-identity-and-associating-users-with-todoes/

+0

私は感覚でこれをやってユーザーを関連付けることによって、保護されたユーザデータとASP.NETコアアプリケーションを作成します。学習..あなたがasp.net MVCを学ぶための良い方法は何ですか? – Adil

関連する問題