Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Roles.GetAllRoles()错误-不包含定义_C#_Roles - Fatal编程技术网

C#Roles.GetAllRoles()错误-不包含定义

C#Roles.GetAllRoles()错误-不包含定义,c#,roles,C#,Roles,我试图在我的C#应用程序中获得所有角色 当我从以下位置复制C#代码时: 进入一个单一的aspx页面,完全按照他们的例子,然后页面工作,我可以看到的角色,并添加一个正确的 当我有以下代码隐藏代码时: using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Security; nam

我试图在我的C#应用程序中获得所有角色

当我从以下位置复制C#代码时: 进入一个单一的aspx页面,完全按照他们的例子,然后页面工作,我可以看到的角色,并添加一个正确的

当我有以下代码隐藏代码时:

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();
            }

        }
    }
}
我的aspx页面:

<%@ 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>

角色

我收到以下错误:“ToolingPMv2.Admin.Access.Roles”不包含“GetAllRoles”的定义

我想如果我有“使用System.Web.Security”,我可以访问这个方法


我做错了什么?这似乎是我现在应该知道的最基本的一课。

页面的类名为
Roles
,因此它将一个隐藏在另一个命名空间中。您需要明确,例如:

rolesArray = System.Web.Security.Roles.GetAllRoles();

大卫,是的,就是这样。非常感谢。