ASP.NET MVC角色没有数据库(无需角色提供) [英] ASP.NET MVC Roles without database (and without role provider)

查看:283
本文介绍了ASP.NET MVC角色没有数据库(无需角色提供)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用RpxNow(OpenID的),以允许用户登录一个超级简单的ASP.NET MVC应用程序。我现在希望让用户编辑自己的帐户,并提供管理员访问权限编辑任何人的帐户。

我有两个单独的编辑帐户的意见:


  • 〜/帐号/编辑/

  • 〜/帐号/编辑/ 1

在第一次加载基于登录的用户帐户的详细信息。第二个加载使用提供的帐户ID帐户详细信息。第一是为标准的用户,并且第二管理员

首先,我需要定义角色(用户,管理员),然后我需要的用户帐户(或多个)分配给该角色。

这时我需要检查在控制器中的作用。我喜欢这个概念:

http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/

所以,下到的问题:


  1. 有没有一种简单的方法在web.config中定义的角色列表?

  2. 有没有一种简单的方法来定义哪些用户是哪些角色在web.config?

  3. 有没有办法做到不使用会员/角色提供?

  4. 是我从错误的角度接近这一点?我应该partioning应用分为两个分支和基于文件夹的权限保护他们?


解决方案

我不是存储在web.config中的授权数据的一个朋友。我preFER将其存储在数据库或其他XML文件。

看一看<一个href=\"http://learn.iis.net/page.aspx/528/how-to-use-the-sample-read-only-xml-membership-and-role-providers-with-iis-70/\"相对=nofollow> XML会员/角色提供。这使用会员/角色读取用户数据,但它显示了一种方法存储和从XML文件中读取用户授权数据。

Braching应用woulded移动问题,而不是解决的。

I have a super simple ASP.NET MVC application that uses RpxNow (OpenID) to allow users to login. I now want to let users edit their own account and provide administrator access to edit anyone's account.

I have two separate "Edit Account" views:

  • ~/account/edit/
  • ~/account/edit/1

The first loads the account details based on the logged in user. The second loads the account details using the supplied AccountId. The first would be for standard users, and the second for an administrator.

Firstly I need to define the roles (User, Admin) and then I need to assign a user account (or multiple) to that role.

Then I need to check the role in the controller. I like this concept:

http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/

So, down to the questions:

  1. Is there a simple way to define a list of roles in the web.config?
  2. Is there a simple way to define which users are in which roles in the web.config?
  3. Is there a way to do this WITHOUT using Membership / Role providers?
  4. Am I approaching this from the wrong perspective? Should I be partioning the application into two branches and securing them based on folder authorisation?

解决方案

I'm not a friend of storing authorization data in web.config. I prefer storing it in database or other xml files.

Have a look at Xml Membership / Role Provider. This uses Membership / Role for reading userdata but it shows a way storing and reading user authorization data from xml files.

Braching the application woulded move the issue and not solve.

这篇关于ASP.NET MVC角色没有数据库(无需角色提供)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆