System.Configuration.ConfigurationErrorsException未被用户代码处理,Message =无法加载文件或程序集'System.Web

时间:2014-01-20 00:17:45

标签: c# asp.net .net asp.net-mvc asp.net-mvc-4

我已阅读以下文章http://msdn.microsoft.com/en-us/library/ff650307.aspx,关于我如何从多个域验证asp.net mvc用户,所以在我的asp.net mvc中我做了以下内容: -

我在web.config中添加了以下内容: -

<system.web>
    <membership>
      <providers>
        <add name="TestDomain1ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web,               Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="TestDomain1ConnectionString" connectionUsername="ad-domainA.intra\it360ad.user" connectionPassword="$$$$$" />

      </providers>
    </membership>

&安培;

<connectionStrings>

<add name="TestDomain1ConnectionString" connectionString="LDAP://ad-domainA.intra/CN=Users,DC=ad-domainA,DC=intra" />

我添加了以下Account.controller: -

[AllowAnonymous]
        public ActionResult Login(string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;
            return View();
        }

        //
        // POST: /Account/Login

        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult Login(LoginModel model, string returnUrl)
        {


            MembershipProvider domainProvider;

            domainProvider = Membership.Providers["TestDomain1ADMembershipProvider"];


            // Validate the user with the membership system.
            if (domainProvider.ValidateUser(model.UserName, model.Password))
            {

                if (Request.QueryString["ReturnUrl"] != null)
                {

                    FormsAuthentication.RedirectFromLoginPage(
                        model.UserName, false);
                }
                else
                {
                    // If there is no RequestUrl query string attribute, just set
                    // the authentication cookie. Provide navigation on the login page
                    // to pages that require authentication, or user can use browser
                    // to navigate to protected pages.
                    // Set second parameter to false so cookie is not persistent
                    // across sessions.
                    FormsAuthentication.SetAuthCookie(model.UserName, false);
                }
            }
            else
        {

            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }

            return RedirectToLocal(returnUrl);

        }

但是当我在登录界面中输入我的用户名和密码并点击回车时,我收到以下错误: -

  

System.Configuration.ConfigurationErrorsException未处理   用户代码HResult = -2146232062消息=无法加载文件或   汇编&#39; System.Web,Culture = neutral,   公钥= b03f5f7f11d50a3a&#39;或其中一个依赖项。该   系统找不到指定的文件。   (C:\ Users \ john.john \ Desktop \ test login \ TMS \ TMS \ web.config第39行)
  Source = System.Web BareMessage =无法加载文件或程序集   &#39; System.Web,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a&#39;或者一个   它的依赖关系。系统找不到指定的文件   Filename = C:\ Users \ john.john \ Desktop \ test login \ TMS \ TMS \ web.config
  Line = 39 StackTrace:          在System.Web.Security.Membership.Initialize()          at System.Web.Security.Membership.get_Providers()InnerException:System.IO.FileNotFoundException          的HResult = -2147024894          Message =无法加载文件或程序集System.Web,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a&#39;或其中一个   依赖。该系统找不到指定的文件。          来源= mscorlib程序          FileName = System.Web,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a          FusionLog ====预绑定状态信息===日志:用户= AD-ITSERVICES \ john.john日志:DisplayName = System.Web,   Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a(Partial)WRN:   为程序集提供了部分绑定信息:WRN:   程序集名称:System.Web,Culture = neutral,   PublicKeyToken = b03f5f7f11d50a3a |域ID:4 WRN:部分绑定   仅在提供部件装配显示名称时发生。警告:   这可能导致装订器装入错误的装配。警告:它   建议为。提供完全指定的文本标识   汇编,WRN:由简单的名称,版本,文化和   公钥令牌。警告:见白皮书   http://go.microsoft.com/fwlink/?LinkId=109270了解更多信息和   这个问题的常见解决方案。日志:Appbase =   file:/// C:/Users/john.john/Desktop/test login / TMS / TMS / LOG:Initial   PrivatePath = C:\ Users \ john.john \ Desktop \ test login \ TMS \ TMS \ bin   调用程序集:(未知)。   ===日志:此绑定在默认加载上下文中启动。日志:使用应用程序配置文件:C:\ Users \ john.john \ Desktop \ test   login \ TMS \ TMS \ web.config日志:使用主机配置文件:   C:\ Users \ john.john \ Documents \ IISExpress \ config \ aspnet.config日志:   使用来自的机器配置文件   C:\ WINDOWS \ Microsoft.NET \框架\ v4.0.30319 \ CONFIG \ machine.config中。   日志:此时政策未适用于参考(私人,   自定义,部分或基于位置的程序集绑定)。日志:正在尝试   下载新的URL   file:/// C:/Users/john.john/AppData/Local/Temp/2/Temporary ASP.NET   文件/根/ 2fc69b03 / 2c0137b8 / System.Web.dll中。日志:尝试下载   新的URL文件:/// C:/Users/john.john/AppData/Local/Temp/2/Temporary   ASP.NET Files / root / 2fc69b03 / 2c0137b8 / System.Web / System.Web.DLL。日志:   试图下载新的URL文件:/// C:/Users/john.john/Desktop/test   登录/ TMS / TMS /斌/ System.Web.dll中。日志:尝试下载新网址   文件:/// C:/Users/john.john/Desktop/test   登录/ TMS / TMS /斌/的System.Web / System.Web.dll中。日志:尝试下载   新的URL文件:/// C:/Users/john.john/AppData/Local/Temp/2/Temporary   ASP.NET Files / root / 2fc69b03 / 2c0137b8 / System.Web.EXE。日志:正在尝试   下载新的URL   file:/// C:/Users/john.john/AppData/Local/Temp/2/Temporary ASP.NET   文件/根/ 2fc69b03 / 2c0137b8 / System.Web程序/ System.Web.EXE。日志:   试图下载新的URL文件:/// C:/Users/john.john/Desktop/test   登录/ TMS / TMS /斌/ System.Web.EXE。日志:尝试下载新网址   文件:/// C:/Users/john.john/Desktop/test   登录/ TMS / TMS /斌/的System.Web / System.Web.EXE。

   StackTrace:
        at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly,
     

StackCrawlMarkHandle stackMark,IntPtr pPrivHostBinder,Boolean   loadTypeFromPartialName,ObjectHandleOnStack类型)               at System.RuntimeTypeHandle.GetTypeByName(String name,Boolean throwOnError,Boolean ignoreCase,Boolean reflectionOnly,   StackCrawlMark&安培; stackMark,IntPtr pPrivHostBinder,Boolean   loadTypeFromPartialName)               at System.RuntimeType.GetType(String typeName,Boolean throwOnError,Boolean ignoreCase,Boolean reflectionOnly,   StackCrawlMark&安培; stackMark)               at System.Type.GetType(String typeName,Boolean throwOnError,Boolean ignoreCase)               在System.Web.Compilation.BuildManager.GetType(String typeName,Boolean throwOnError,Boolean ignoreCase)               在System.Web.Configuration.ConfigUtil.GetType(String typeName,String propertyName,ConfigurationElement configElement,   XmlNode节点,Boolean checkAptcaBit,Boolean ignoreCase)          的InnerException:

在帐户控制器内的以下代码行: -

public ActionResult Login(LoginModel model, string returnUrl)
        {MembershipProvider domainProvider;
domainProvider = Membership.Providers["TestDomain1ADMembershipProvider"];

那是什么导致了这个错误?

1 个答案:

答案 0 :(得分:1)

对于System.Web的这个声明

System.Web, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

还需要版本(4.0对吗?)

Version=4.0.0.0