I am trying to get all Roles in my C# application.
When I copy the C# code from: https://docs.microsoft.com/en-us/dotnet/api/system.web.security.roles.getallroles?view=netframework-4.8
into a single aspx page exactly as they have the example then the page works and I can see the Roles and add one properly.
When I have the following code-behind code:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
namespace ToolingPMv2.Admin.Access
{
public partial class Roles : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[] rolesArray;
rolesArray = Roles.GetAllRoles();
RolesGrid.DataSource = rolesArray;
RolesGrid.DataBind();
}
}
}
}
My aspx page:
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.Master" CodeBehind="UserRoles.aspx.cs" Inherits="ToolingPMv2.Admin.Access.Roles" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<h2>Roles</h2>
<br />
<asp:GridView runat="server" CellPadding="2" id="RolesGrid" Gridlines="Both" CellSpacing="2" AutoGenerateColumns="false" >
<HeaderStyle BackColor="navy" ForeColor="white" />
<Columns>
<asp:TemplateField HeaderText="Roles" >
<ItemTemplate>
<%# Container.DataItem.ToString() %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Content>
I get the following error: 'ToolingPMv2.Admin.Access.Roles' does not contain a definition for 'GetAllRoles'
I thought that if I have 'Using System.Web.Security' I could access this method.
What am I doing wrong? This seems like a basic fundamental lesson that I should know by now.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…