授权标签如何工作? - ASP.NET MVC
授权标签如何判断用户是否获得授权?
例如,如果用户登录并尝试进入具有授权标签的视图。它如何判断用户是否被授权?它是否对数据库进行查询并检查?
如果他们进入具有角色授权的视图怎么样?它是否查询成员角色表?
我只是想知道,因为我有 ASP.NET 成员资格表认为重复的用户名。我使用一系列字段来确定哪个用户是什么,允许用户具有相同的重复用户名,但在我的数据库中仍然是唯一的。
这导致我必须为大量 .NET 成员资格内容编写自定义方法,因为它们都使用“userName”而不是使用 UserId 进行搜索。
所以我现在想知道授权标签是否会出现这种情况。因为我不知道它是如何工作的,并且如果我不使用 .NET 成员身份,我也不知道它将如何确定它。
How does the Authorize Tag determine if the user is authorized or not?
Like say, if a user logs in and they try to go to a view that has an Authorize tag. How does it determine if a user is authorized or not? Does it do a query to database and check?
How about if they go to a view with a role authorization? Does it query the membership role table?
I am just wondering since I have what the ASP.NET membership tables considers duplicate userNames. I use a serious of fields to determine which user is what, allowing users to have the same duplicate userName, but still be unique in my database.
This caused me to have to write custom methods for lots of .NET membership stuff since it all used "userName" to do searching instead of using the UserId.
So I am now wondering if this could be the case with the Authorize tag. Since I have no clue how it works and like if I was not using .NET membership I would not have a clue how it would determine it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Authorize
标记使用 ASP.NET 中的所有内置成员资格检查。滚动自己的标签非常容易。例如:然后您可以使用
[MyAuthorize]
标记,该标记将使用您的自定义检查。The
Authorize
tag uses all the built in membership checks from ASP.NET. It's VERY easy to roll your own tag. For example:You then can use the
[MyAuthorize]
tag which will use your custom checks.ControllerActionInvoker 解析属性并调用
OnAuthorization ()
当需要检查凭据时。AuthorizationAttribute.OnAuthorization()
方法主要检查User.Identity.IsAuthenticated
是否为 true。这只是利用了 FormsAuthentication 或您可能使用的任何其他身份验证方案的功能。ControllerActionInvoker parses the attribute and calls
OnAuthorization()
on it when it's time to check the credentials.The
AuthorizationAttribute.OnAuthorization()
method basically checks to see ifUser.Identity.IsAuthenticated
is true or not. This just draws on the functionality of FormsAuthentication or whatever other authentication scheme you may be using.