views:

123

answers:

4

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="~/Content/images/buttons/btn_rnd_save.png" alt="Yes" />
            <% } else { %>
            <asp:Image runat="server" ImageUrl="~/Content/images/buttons/btn_Close.gif" alt="No" />
          <% } %>           
          </td>
A: 

Have you imported System.Web.Security

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

Prakash Kalakoti
i already did that <%@ Import Namespace="System.Web.Security" %>
Pinu
A: 

System.Web.ApplicationServices

Simon Hazelton
A: 

System.Web.ApplicationServices for .NET 4.0

System.Web.Security for .NET 3.5

Andrew Lewis
The class remained the same, but they moved it to a different dll/namespace.
Andrew Lewis
@Andrew,I tried adding both of them but it stil does the same
Pinu
A: 

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>
GalacticCowboy
I did every thing mentioned in this link,but still it does the same thing? any thing else i need to look at?
Pinu
Have you created an ASP.NET security database? Or, are you using the Windows Active Directory providers? Do you have authentication (logging in/out) working? Have you assigned users to roles?
GalacticCowboy
I am using the ASP.NET database , one provided by asp.net membership provider. I am able to login and i have about 80 users add in the database and 5 roles created.
Pinu