如何设置aspnetrules的规则? [英] How to set rules on aspnetrules?
问题描述
Hello Guys,
我对如何在AspNetRules上将规则设置为Adminclient普通用户感到困惑
我所做的是:
1.我创建了一个MVC项目
2.与我的本地db sql server管理工作室建立连接字符串
3.我执行了应用程序,并创建了第一个用户,以便在我的数据库上创建所有表。正如你在下面看到的那样
我尝试过:
你好伙计们,
我对如何在AspNetRules上将规则设置为管理员客户端普通用户感到困惑
我所做的是:
1.我创建了一个MVC项目
2.与我的本地db sql server管理工作室建立连接字符串
3.我执行了应用程序,并创建了第一个用户,以便在我的数据库上创建所有表。如下所示
参见图片
我在控制器上尝试了什么 - > AccountController.cs
Hello Guys,
I am bit confused on how to set rules as "Admin" "client" "normal user" on AspNetRules
What I have done is:
1. I created a MVC project
2. Made a connection string with my local db sql server management studio
3. I executed the application, and created the first user, in order to create all the tables on my db. As you can see below
What I have tried:
Hello Guys,
I am bit confused on how to set rules as "Admin" "client" "normal user" on AspNetRules
What I have done is:
1. I created a MVC project
2. Made a connection string with my local db sql server management studio
3. I executed the application, and created the first user, in order to create all the tables on my db. As you can see below
See Image
What I have tried to on Controllers --> AccountController.cs
//
// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task Register(RegisterViewModel model)
{
if (!ModelState.IsValid) return View(model);
var user = new ApplicationUser() { UserName = model.UserName };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
try
{
using (var dal = new DALEF.WebShopEntities())
{
dal.Client.Add(
new DALEF.Client{
CLI_Nom = model.Nom,
CLI_Prenom = model.Prenom,
CLI_Civilite = model.Civilite,
CLI_Email = model.Email,
CLI_Adresse = model.Adresse,
CLI_CodePostal = model.CodePostal,
CLI_Ville = model.Ville,
CLI_Telephone = model.Telephone,
CLI_AspUser_Id = user.Id
});
dal.SaveChanges();
}
}
catch (Exception)
{
// client n'est pas ajouté delete l'asp user créé
ModelState.AddModelError("", "Echec création client, veuillez réessayer");
return View(model);
}
//await UserManager.AddToRoleAsync(user.Id, "client");
await SignInAsync(user, isPersistent:false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}
但是当我创建新用户时,收到错误:
< a href =http://csharpcorner.mindcrackerinc.netdna-cdn.com/forums/uploadfile/03e4db/01252017064700AM/Cattura1.PNG>点击这里
当我检查数据库时,我看到用户已创建,但不是规则。
如何创建规则?只是非常简单的规则,如管理员或普通用户,以便为视图创建[授权]。
提前感谢。
But when I create a new user, I receive an error:
Click here
When I check the db, i see that the user is created, but not the rule.
How can I create rules? Just very simple rules as "Admin" or "Normal user", in order to create the [Authorize] for the Views.
Thanks in advance.
推荐答案
感谢 Richard Deeming 我到达为每个用户创建分配规则。
我所做的是:
- 手动创建admin和client规则
- 每次用户注册时,他都会获得客户端规则。
:)
Thanks to Richard Deeming I arrived to assign rules to each user creation.
What I have done is:
- created manually the "admin" and "client" rule
- and each time that a user is registering, he got the client rule.
:)
这篇关于如何设置aspnetrules的规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!