本文介绍了角色" A"没有被发现,并给出System.Configuration.Provider.ProviderException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实我已经使用这个code创建了一个名为A的角色:

Actually i have created a role called "A" by using this code:

exec aspnet_Roles_CreateRole
@ApplicationName  = 'Application name',
@RoleName         = 'A'

而现在我需要这个角色添加到用户。有一个在我的应用程序和previously它与其他角色,仍然良好的工作角色的列表。但是,这个新角色不会被添加并引发错误为:

And now i need to add this role to a user. There is a list of role in my application and previously it was working with other roles and still good. But this new role is not added and throws the error as:

System.Configuration.Provider.ProviderException:角色'A'未找到

这是我的C#code:

This is my C# code:

protected void btnSave_Click(object sender, EventArgs e)
{
    //Find Name
    lblMsg.Visible = false;
    nameLabel.Text = "";
    PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
    UserPrincipal qbeUser = new UserPrincipal(ctx);
    PrincipalSearcher srch;

    try
    {
        qbeUser.SamAccountName = userTextBox1.Text;
        srch = new PrincipalSearcher(qbeUser);
    }
    catch
    {
        lblMsg.Visible = true;
        lblMsg.Text = " Employee filed is Empty !  ";
        lblMsg.CssClass = "faild";

        return;
    }
    foreach (var found in srch.FindAll())
    {
      DirectoryEntry de = found.GetUnderlyingObject() as DirectoryEntry;

        nameLabel.Text = Convert.ToString(de.Properties["GivenName"].Value);
        principleLabel.Text = Convert.ToString(de.Properties["UserPrincipalName"].Value);
    }
    if (nameLabel.Text == "")
    {
        lblMsg.Visible = true;
        lblMsg.Text = " Username is not found   ";
        lblMsg.CssClass = "faild";
        return;
    }
    List<string> User_Roles_List = new List<string>();
    for (int i = 0; i < chkSetup.Items.Count; i++)
        if (chkSetup.Items[i].Selected)
            User_Roles_List.Add(chkSetup.Items[i].Value);
    for (int i = 0; i < chkEmployee.Items.Count; i++)
        if (chkEmployee.Items[i].Selected)
            User_Roles_List.Add(chkEmployee.Items[i].Value);
    for (int i = 0; i < chkShift.Items.Count; i++)
        if (chkShift.Items[i].Selected)
            User_Roles_List.Add(chkShift.Items[i].Value);
    for (int i = 0; i < chkAttendance.Items.Count; i++)
        if (chkAttendance.Items[i].Selected)
            User_Roles_List.Add(chkAttendance.Items[i].Value);
    for (int i = 0; i < chkSite.Items.Count; i++)
        if (chkSite.Items[i].Selected)
            User_Roles_List.Add(chkSite.Items[i].Value);
    for (int i = 0; i < chkPayroll.Items.Count; i++)
        if (chkPayroll.Items[i].Selected)
            User_Roles_List.Add(chkPayroll.Items[i].Value);
    for (int i = 0; i < chkOthers.Items.Count; i++)
        if (chkOthers.Items[i].Selected)
            User_Roles_List.Add(chkOthers.Items[i].Value);

    string[] current_roles = Roles.GetRolesForUser(userTextBox1.Text);
    if (current_roles.Length != 0)
        Roles.RemoveUserFromRoles(userTextBox1.Text, current_roles);
    Roles.AddUserToRoles(userTextBox1.Text, User_Roles_List.ToArray());  //Error occur at this line
    lblMsg.Visible = true;
    lblMsg.CssClass = "successfull";
    lblMsg.Text = "Roles have been successfully updated";
}

我用Google搜索了很多,但没有得到实际的解决方案。 u能请告诉我,我在哪里做的错误?

I have googled a lot but didn't get the actual solution. Can u please tell me where am i making the mistake?

推荐答案

这可能会帮助你在这种情况下。

This might help you in this case.

在您的Microsoft Visual Studio中,转到网站,并点击Asp.net配置
然后在安全选项卡,创建一个名为 A 新角色。
从那里,你可以在Asp.net管理角色分配和用户太

In your Microsoft Visual Studio, Go to "Website" and Click "Asp.net Configuration"and then in "Security" tab, create new role called A.From there you can manage the role assignments and user too in Asp.net

这篇关于角色&QUOT; A&QUOT;没有被发现,并给出System.Configuration.Provider.ProviderException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:14