Custom membership or not

后端 未结 5 644
既然无缘
既然无缘 2021-02-04 14:21

I am creating website (football, soccer) in ASP.NET MVC3 and I want have users (with additional information then user in default membership, these are ordinary visitors) and pla

5条回答
  •  鱼传尺愫
    2021-02-04 15:04

    If you are looking to store profile type information e.g. first name, last name, job title etc. against each user then you should be able to use the Profile system built into ASP.NET Membership. If you are looking to store more identity related information then yes you will have to create some sort of custom membership provider. There is a good video on creating a custom provider on the ASP.NET website: http://www.asp.net/general/videos/how-do-i-create-a-custom-membership-provider

    Regarding allowing different types of users to perform different actions you can use the Roles system built into ASP.NET Membership. You can tell your action methods to only allow calls from users in certain roles. For example if you had a PostArticle action method and you only wanted players to be able to access it you would have something like this:

    [Authorize(Roles="Player")]
    public ActionResult PostArtcile(){
        return View();
    }
    

    The Authorize attribute tells MVC to only allow authenticated users in the "Player" role to call the action method. You'll still need to restrict the availability of a post article link in your front end but there are several ways to do that.

    There is a great series of articles by Scott Mitchell which covers all things membership based: http://www.4guysfromrolla.com/articles/120705-1.aspx

提交回复
热议问题