无法从程序集中加载类型

无法从程序集中加载类型

本文介绍了解析器错误消息:无法从程序集中加载类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的应用程序添加 roleprovider ,但是由于解析器错误而遇到麻烦.

I want to add a roleprovider for my application but i am having troubles because of the parser error.

这是我的文件:

这是我的网络配置:

<roleManager defaultProvider ="roleProvider" enabled="true">
    <providers>
      <add name="roleprovider"  type="MvcApplication6.roleprovider,MvcApplication6"/>
    </providers>
  </roleManager>

我一直在获取该 Parser错误消息:无法从程序集'MvcApplication6'中加载类型'roleprovider'.

我尝试了几种方法,例如添加到 App_code .

I tried several methods such as adding to App_code.

我该如何解决此问题?我尝试了其他解决方案,但它们对我没有用.我可能做错了,所以请帮忙.

How do i resolve this issue? I tried the other solutions but they didn't work for me. I am probably doing it wrong so please help.

推荐答案

您可以创建一个名为 Helper 的文件夹,然后尝试以下操作:

You can create a folder called Helper and try this:

<roleManager cacheRolesInCookie="true" defaultProvider="CustomRoleProvider" enabled="true">
      <providers>
        <clear />
        <add name="CustomRoleProvider" type="MvcApplication6.Helper.CustomRoleProvider"/>
      </providers>
</roleManager>

另一件事:请确保以正确的方式实现CustomRoleProvider:使用系统;使用System.Web.Security;

One more thing: Make sure you implement the CustomRoleProvider in a right way:using System;using System.Web.Security;

namespace MvcApplication6.Helper
{
    public class CustomRoleProvider : RoleProvider
    {
        public override bool IsUserInRole(string username, string roleName)
        {
            if (username.ToLowerInvariant() == "test" && roleName.ToLowerInvariant() == "User")
                return true;
            // blabla ...
            return false;
        }

        public override string[] GetRolesForUser(string username)
        {
            if (username.ToLowerInvariant() == "test")
            {
                return new[] { "User", "Helpdesk" };
            }

            if(username.ToLowerInvariant()=="test2")
            {
                return new [] { "Admin" };
            }

            return new string[] { };
        }

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            throw new NotImplementedException();
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }
    }
}

这篇关于解析器错误消息:无法从程序集中加载类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:17