0
votes

I have read the following article http://msdn.microsoft.com/en-us/library/ff650307.aspx, about how i can authenticate asp.net mvc users from multiple domains, so inside my asp.net mvc i did the following :-

I added the following to my 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" />

and i added the following 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);

        }

but when i type my user name and password inside the login screen and click on enter , i got the following error:-

System.Configuration.ConfigurationErrorsException was unhandled by user code HResult=-2146232062 Message=Could not load file or assembly 'System.Web, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. (C:\Users\john.john\Desktop\test login\TMS\TMS\web.config line 39)
Source=System.Web BareMessage=Could not load file or assembly 'System.Web, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Filename=C:\Users\john.john\Desktop\test login\TMS\TMS\web.config
Line=39 StackTrace: at System.Web.Security.Membership.Initialize() at System.Web.Security.Membership.get_Providers() InnerException: System.IO.FileNotFoundException HResult=-2147024894 Message=Could not load file or assembly 'System.Web, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Source=mscorlib FileName=System.Web, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a FusionLog==== Pre-bind state information === LOG: User = AD-ITSERVICES\john.john LOG: DisplayName = System.Web, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (Partial) WRN: Partial binding information was supplied for an assembly: WRN: Assembly Name: System.Web, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a | Domain ID: 4 WRN: A partial bind occurs when only part of the assembly display name is provided. WRN: This might result in the binder loading an incorrect assembly. WRN: It is recommended to provide a fully specified textual identity for the assembly, WRN: that consists of the simple name, version, culture, and public key token. WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue. LOG: Appbase = file:///C:/Users/john.john/Desktop/test login/TMS/TMS/ LOG: Initial PrivatePath = C:\Users\john.john\Desktop\test login\TMS\TMS\bin Calling assembly : (Unknown). === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users\john.john\Desktop\test login\TMS\TMS\web.config LOG: Using host configuration file: C:\Users\john.john\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Attempting download of new URL file:///C:/Users/john.john/AppData/Local/Temp/2/Temporary ASP.NET Files/root/2fc69b03/2c0137b8/System.Web.DLL. LOG: Attempting download of new URL file:///C:/Users/john.john/AppData/Local/Temp/2/Temporary ASP.NET Files/root/2fc69b03/2c0137b8/System.Web/System.Web.DLL. LOG: Attempting download of new URL file:///C:/Users/john.john/Desktop/test login/TMS/TMS/bin/System.Web.DLL. LOG: Attempting download of new URL file:///C:/Users/john.john/Desktop/test login/TMS/TMS/bin/System.Web/System.Web.DLL. LOG: Attempting download of new URL file:///C:/Users/john.john/AppData/Local/Temp/2/Temporary ASP.NET Files/root/2fc69b03/2c0137b8/System.Web.EXE. LOG: Attempting download of new URL file:///C:/Users/john.john/AppData/Local/Temp/2/Temporary ASP.NET Files/root/2fc69b03/2c0137b8/System.Web/System.Web.EXE. LOG: Attempting download of new URL file:///C:/Users/john.john/Desktop/test login/TMS/TMS/bin/System.Web.EXE. LOG: Attempting download of new URL file:///C:/Users/john.john/Desktop/test login/TMS/TMS/bin/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 type) 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) at System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) at System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) InnerException:

on the following line of code inside the Account controller:-

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

so what is causing this error?

1

1 Answers

1
votes

For this declaration of System.Web

System.Web, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

The version is also needed (4.0 right?)

Version=4.0.0.0