0
votes

I am new on ASP.net MVC, I have this controller that uses Windows authentication (xxxxDMZ\username, password):

[Authorize]
public class ExController : Controller
{ 
    protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    {
        base.Initialize(requestContext);
        ViewBag.user = User.Identity.Name;
    }

    public ActionResult Index()
    {
        return View();
    }
}

Now I need to use a different domain (xxxx\username, password) to access this controller.

web.config:

<system.web>
    <httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>       
    <authentication mode="Windows" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
        <add namespace="GridMvc" />
      </namespaces>
    </pages>
    <membership>
      <providers>
        <clear />
      </providers>
    </membership>
  </system.web>

Current IIS 7.5 configuration: Windows Authentication Enabled(enabled providers: Negotiate, NTLM), Anonymous Authentication Enabled

Notes:

  • the website is hosted in server that can be accessed via RDC by using xxxDMZ\username.
  • xxxDMZ\username and xxx\username is totally different accounts.
  • when the user login to windows, he uses this account xxx\username.
  • I want users to browse the website without using credentials, I only need them to use credentials(xxxx\username, password) when trying to access the controller mentioned above.
  • My problem is not all (xxxx\username, password) users have (xxxxDMZ\username, password) accounts.
1
How is this related to LDAP? is it an option to let the application pool that runs your website run under the account that you want? - Yacoub Massad
Well I don't know, I got that from an answer from my previous post regarding the same issue: link. - Sadiq Thamir
Are you hosting your site in IIS? what are the settings for IIS authentication? Is it windows authentication? Did you enable ASP.NET impersonation in IIS authentication? do you want this code to execute under the windows account of the user that is viewing the site? - Yacoub Massad
Yes I am hosting it on IIS 7.5. the authentications are now set for both windows authentication and anonymous authentication. ASP.NET impersonation is not enabled. Yes I want this code to be executed under the windows account of the user - Sadiq Thamir
Why do you need to enable anonymous authentication? If you don't need it, disable it. Enable ASP.NET impersonation and then test. - Yacoub Massad

1 Answers

0
votes

I suppose that You need to configure an ActiveDirectoryMembershipProvider for your authentication.

web.config :

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
      <authentication mode="Forms">
          <forms name=".ADAuthCookie" loginUrl="~/Account/Login" timeout="45" slidingExpiration="false" protection="All" />
      </authentication>
      <membership defaultProvider="ADMembershipProvider">
          <providers>
              <clear />
              <add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName" />
          </providers>
      </membership>
  </system.web>
  <connectionStrings>
      <add name="ADConnectionString" connectionString="LDAP://primary.mydomain.local:389/DC=MyDomain,DC=Local" />
  </connectionStrings>
</configuration>

Please refer to http://www.schiffhauer.com/mvc-5-and-active-directory-authentication/