Last post Feb 27, 2013 07:46 PM by stargate2k
Feb 27, 2013 07:04 PM|stargate2k|LINK
i have created a ASP MVC 4 RAZOR standard-application and i have created my own Database where i store Username and Password. And i use FormAuthentification i have set a Cookie with the Username.
When i use my own DB the [Authorize] and [AllowAnonymous] Tag did not work. Is it possible that i can use this tag's with my DB ? Or how can i say that the loggedin User X has only access to Controller A Action B ?
I have read that i can here http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5-web-forms-and-asp-net-mvc-4-templates.aspx
use my own DB with the "WebSecurity.InitializeDatabaseFile"
I have now created a new standard mvc4 razor project an i have create in AppData a DatabaseSimple.mdf with a "Users" Table.. i added iD,Username,Passwort,Email and the link above says, i must execute this--> "WebSecurity.InitializeDatabaseFile(“DatabaseSimple.mdf”,
“Users”, “Id”, “Username”, true);" i have put this in a _start.cshtml file in my View directory. but it seem this would not executed ? this command should normally create a few more Table´s in my DB ? but i have only my Users Table.. and why has the example
in the Link no Password field ?
Feb 27, 2013 07:22 PM|BrockAllen|LINK
Just to help clear the air a bit, membership and simplemembership are just databases -- nothing else. Forms auth is what tracks the logged in user so the app knows their idenitty. Authorization is then simply checking access rules against the user's identity
And here's a simple approach to augment the username with roles:
Feb 27, 2013 07:46 PM|stargate2k|LINK
i I thought i create a DB with Username and Password and if i execute the WebSecurity.InitializeDatabaseFile it adds the Tables for Role-Management to my existing DB..
How can i add Rolle Management to my existing DB ?
I want that i can say UserX is the Admin and can Access all Views and UserY is a normal user and can access only a couple of views.
My current Login Action..
public ActionResult Login(LocalLoginModel acc)
if (validate(acc)) // Checks if User and PW correct
ModelState.AddModelError("", "Wrong Username or Password");
ViewBag.DB = "false";
and the [Authorize] or [AllowAnonymous] Tag did not work...
i want say [Authorize(Roles="admin")] can only acces the admin page of my site. or what is the easiest way to do that ?
)] can only acces the admin page of my site. or what is the easiest way to do that ?
Best regards stargate