title: Single sign on inside asp.net mvc web application
body: <p>I have two domains ,on our internal network:-</p>
  
  <ol>
  <li>DomainA</li>
  <li>DomainB</li>
  </ol>
  
  <p>Both domains can communicate with each other’s, but they do <strong>NOT</strong> trust each other.</p>
  
  <p>So currently I have deployed my asp.net MVC web application inside domainA on IIS, but I need users who are on DomainB Active directory to be able to login to the asp.net mvc using their domainB AD credentials . I am open to both windows authentication and form authentication inside my asp.net mvc . </p>
  
  <p>But the only requirement that came from the client is that they want users who access the asp.net mvc intranet application from their machine on domainB, to be able to lo-gin to the system without having a login page;  they can either:-</p>
  
  <ol>
  <li>enter the username and password through the browser pop-up, </li>
  <li>or to sign in automatically.</li>
  </ol>
  
  <p>So can anyone advice what are the approaches I can follow, to achieve this?
  Thanks</p>
  
  <p><strong>EDIT</strong>
  I have read the following article <a href="http://msdn.microsoft.com/en-us/library/ff650307.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ff650307.aspx</a>, about how i can authenticate asp.net mvc users from multiple domains, so inside my asp.net mvc i did the following :-</p>
  
  <p>I added the following to my web.config:-</p>
  
  <pre><code>&lt;system.web&gt;
      &lt;membership&gt;
        &lt;providers&gt;
          &lt;add name="TestDomain1ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="TestDomain1ConnectionString" connectionUsername="ad-domainA.intra\it360ad.user" connectionPassword="$$$$$" /&gt;
  
        &lt;/providers&gt;
      &lt;/membership&gt;
  </code></pre>
  
  <p>&amp;
      </p>
  
  <pre><code>&lt;add name="TestDomain1ConnectionString" connectionString="LDAP://ad-domainA.intra/CN=Users,DC=ad-domainA,DC=intra" /&gt;
  </code></pre>
  
  <p>and i added the following Account.controller:-</p>
  
  <pre><code>[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 there is a RequestUrl query string attribute, the user has
          // been redirected to the login page by forms authentication after
          // requesting another page while not authenticated.
          if (Request.QueryString["ReturnUrl"] != null)
          {
              // RedirectFromLoginPage sets the authorization cookie and then
              // redirects to the page the user originally requested.
              // Set second parameter to false so cookie is not persistent
              // across sessions.
              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
      {
        //  Response.Write("Invalid UserID and Password");
          ModelState.AddModelError("", "The user name or password provided is incorrect.");
          return View(model);
      }
      ////////////
      //if (ModelState.IsValid &amp;&amp; WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
      //{
          return RedirectToLocal(returnUrl);
      //}
  
      // If we got this far, something failed, redisplay form
  
  }
  </code></pre>
  
  <p>But currently when the user try to login , he will get always the following message </p>
  
  <pre><code>•The user name or password provided is incorrect. 
  </code></pre>
  
  <p>so can you advice if my code is correct ?</p>