2
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%
if (Request.IsAuthenticated) {
%>
Welcome <b><%= Html.Encode(Page.User.Identity.Name) %></b>!
[ <%= Html.ActionLink("Log Off", "LogOff", "Account") %> ]
<br />
<% if(User.IsInRole("Administrator")) { %>
<br />
<%= Html.ActionLink("Home", "Index", "Home") %> | <%= Html.ActionLink("About", "About", "Home") %> | <%= Html.ActionLink("UserControl","UserControl","Account")%>
<% } else { %>
<br />
<%= Html.ActionLink("Home", "Index", "Home") %> | <%= Html.ActionLink("About", "About", "Home") %>
<%} %>
我想检查用户的角色,如果它是管理员只有那么用户可以看到用户control.when链接,当我尝试运行此代码它给我一个错误说 “'Data.User'不包含'IsInRole'的定义”ASP.Net MVC检查用户在aspnet中的角色