开发者

asp.net mvc -> Roles.IsUserInRole(username,role)

Do we need to add any references or import any namespace for Roles.IsUserInRole(username,role) - > is it not giving the right result.

<% if(Model.Count < 1)
    {%>
        No User's Add Under You!
    <% } else {
        foreach (var item in Model) { %>
    <tr class="tblheader">
        <th> User Name </th>
        <th> Last Activity      </th>
        <th> Administrator     </th>
        <th> Base User    </th>
        <th> Print User    </th>
        <th> SDI User </th>
        <th> Edit User         </th>
    </tr>
    <% if(Model.Count < 1)
    {%>
        No User's Add Under You!
    <% } else {
        foreach (var item in Model) { %>

<td class="usertd">
            <%if(Roles.IsUserInRole(item.UserName,"Administrator")) { %>
             <asp:Image runat="server" ImageUrl="~/Content/images/buttons/btn_rnd_save.png" alt="Yes" />
            <% } else { %>
            <asp:Image runat="server" ImageUrl="~/Content/images/buttons/btn_Close.gif" alt="No" />
          <% } %>           
          </td>
            <td class="usertd">
            <%if(Roles.IsUserInRole(item.UserName,"BaseUser")) { %>
             <asp:Image runat="server" ImageUrl="~开发者_Go百科/Content/images/buttons/btn_rnd_save.png" alt="Yes" />
            <% } else { %>
            <asp:Image runat="server" ImageUrl="~/Content/images/buttons/btn_Close.gif" alt="No" />
          <% } %>           
          </td>


Have you imported System.Web.Security

For more details on this you can check http://msdn.microsoft.com/en-us/library/bz1zy88e.aspx


System.Web.ApplicationServices for .NET 4.0

System.Web.Security for .NET 3.5


You need to enable the RoleManager in web.config, as it is disabled by default.

<roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider">
  <providers>
    <clear/>
    <add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </providers>
</roleManager>


System.Web.ApplicationServices


If you set a breakpoint at

IsUserInRole
, is it hit?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜