簡單的會員管理帳戶 (Simple Membership Admin Accout)


問題描述

簡單的會員管理帳戶 (Simple Membership Admin Accout)

我正在開發我的第一個 ASP.Net MVC 4 應用程序,現在堅持使用一個簡單的用例。

我需要對一個用戶(管理員)進行身份驗證,以便他/她可以登錄到管理區域執行某些任務。雖然 ASP.Net 互聯網項目模板具有使用簡單成員資格的帳戶控制器,但這似乎比我實際需要的要多得多。例如,我真的不需要用戶註冊功能和用戶角色。我的要求相當簡單,只需在數據庫中存儲一個用戶,讓他可以選擇更新他的信息,如密碼、電子郵件等,並授予他訪問管理區域(管理控制器和操作)的權限。我想不通的是

  1. 對於這個簡單的場景,我的唯一選擇是簡單的會員資格還是其他asp.net會員資格提供者。

  2. 參考解法

    方法 1:

    You can build a custom method to grab the user and their stored role, then evaluate it in your controller. So, for instance:

    public ActionResult GetAdminPage()
    {
        var loggedInUserName = HttpContext.User.Identity.Name;
        var user = somesortofproviderlookupmethod(loggedInUserName);
    
        // Assume user is a bool and is true
        if (user)
        {
            return view("AdminPage");
        }
    }
    

    The only thing I'm not sure of is whether or not HttpContext.User requires membership. Perhaps someone can shed some light. If so, perhaps you could send the username from the view, but then of course you're trusting the client. So how you are doing user authentication would change this answer somewhat.

    Personally, I like membership. It's clean, easy, fast and can be scaled nicely if you end up having additional requirements. Doing something like this would be even easier with membership, since then you can actually use Roles.GetRolesForUser(); and only return the admin view if they contain the role you are looking for.

    (by ZedBeeDavid L)

    參考文件

    1. Simple Membership Admin Accout (CC BY‑SA 2.5/3.0/4.0)

#asp.net-membership #asp.net-mvc #C#






相關問題

更改會員等級時區 (change membership class time zone)

將 AspNetSqlMembershipProvider 用戶遷移到 WebMatrix (Migrate AspNetSqlMembershipProvider users to WebMatrix)

Beberapa aplikasi dengan keanggotaan dan nama aplikasi yang sama (Multiple applications with membership and same applicationName)

簡單的會員管理帳戶 (Simple Membership Admin Accout)

如何設置 RIA 服務以使用現有的 ASP.Net 成員基礎 (How to setup RIA Services to use an existing ASP.Net membership base)

具有多個數據庫或提供程序的 MVC4 簡單成員身份驗證 (MVC4 Simple Membership authentication with multiple databases or providers)

班級設計決策 (Class design decision)

從 Web.Config 獲取 MembershipProvider 的屬性 (Get MembershipProvider's Properties from Web.Config)

會員 API WP7 (Membership API WP7)

模擬會員 (Mocking Membership)

如何使用 LINQ 和 ASP.NET MVC 持久化用戶與其關聯的數據庫? (How do I persist which database a user is associated with it using LINQ and ASP.NET MVC?)

關於在 Web 應用程序中使用 ASP.NET 安全性和成員資格 (About using ASP.NET security and Membership in web applications)







留言討論