2014-12-02 55 views
0

我一直在内部开发密码重置工具。 该工具使用Windows身份验证(Intranet应用程序)。 这个测试在本地运行时很完美,但是当我发布到IIS并发送解锁或重置命令时,它使用iis服务器的计算机帐户联系AD(显然然后它没有解锁或重置的权限)ASP.Net/IIS认证问题

附件是我的网络配置文件

<?xml version="1.0" encoding="utf-8"?> 

<configuration> 

    <configSections> 
     <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
     <section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler, dotless.Core" /> 
    </configSections> 

    <appSettings> 
     <add key="webpages:Version" value="3.0.0.0" /> 
     <add key="webpages:Enabled" value="false" /> 
     <add key="ClientValidationEnabled" value="true" /> 
     <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    </appSettings> 

    <system.web> 
     <compilation debug="true" targetFramework="4.5" /> 
     <httpRuntime targetFramework="4.5" /> 
     <identity impersonate="true"/> 
     <authentication mode="Windows" /> 
     <authorization> 
      <deny users="?" /> 
     </authorization> 
     <httpHandlers> 
      <add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" /> 
     </httpHandlers> 
    </system.web> 

    <runtime> 
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
      <dependentAssembly> 
       <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" /> 
       <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
      </dependentAssembly> 
      <dependentAssembly> 
       <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" /> 
       <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
      </dependentAssembly> 
      <dependentAssembly> 
       <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" /> 
       <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
      </dependentAssembly> 
      <dependentAssembly> 
       <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" /> 
       <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
      </dependentAssembly> 
      <dependentAssembly> 
       <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /> 
       <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> 
      </dependentAssembly> 
      <dependentAssembly> 
       <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
       <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
      </dependentAssembly> 
      <dependentAssembly> 
       <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
       <bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0" /> 
      </dependentAssembly> 
      <dependentAssembly> 
       <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /> 
       <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /> 
      </dependentAssembly> 
      <dependentAssembly> 
       <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
       <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
      </dependentAssembly> 
      <dependentAssembly> 
       <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 
       <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" /> 
      </dependentAssembly> 
      <dependentAssembly> 
       <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" /> 
       <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" /> 
      </dependentAssembly> 
     </assemblyBinding> 
    </runtime> 

    <dotless minifyCss="false" cache="true" web="false" /> 

    <system.webServer> 
     <validation validateIntegratedModeConfiguration="false" /> 
     <handlers> 
      <add name="dotless" path="*.less" verb="*" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" /> 
     </handlers> 
    </system.webServer> 

    <connectionStrings> 
     <add name="CCLPasswordManagementEntities" connectionString="metadata=res://*/Models.PasswordManagementModel.csdl|res://*/Models.PasswordManagementModel.ssdl|res://*/Models.PasswordManagementModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=10.200.123.16;initial catalog=CCLPasswordManagement;persist security info=True;user id=FrameworkAPI;password=a5t3r1x!;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 

    <entityFramework> 
     <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
      <parameters> 
       <parameter value="mssqllocaldb" /> 
      </parameters> 
     </defaultConnectionFactory> 
     <providers> 
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
     </providers> 
    </entityFramework> 

</configuration> 

一定有什么明显我缺少的IIS中我假设的配置。

任何想法,将不胜感激。

这里是重置密码的代码

using (var context = new PrincipalContext(
         ContextType.Domain)) 
        { 
         string userid = userName.Split('\\').LastOrDefault(); 
         if (userid != null) 
         { 
          using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, userid)) 
          { 
           if (user != null) 
           { 
            user.SetPassword(password); 
            user.ExpirePasswordNow(); 
           } 
           else 
           { 
            return false; 
           } 
          } 
         } 
         else 
         { 
          return false; 
         } 
        } 
        return true; 

回答

0

在Active Directory中服务帐户,并使用它。您可以使用代码中的凭据,也可以使用web.config中的模拟元素来模拟此服务帐户:

<identity impersonate="true" userName="DOMAIN\ServiceAccount" password="password"/>

+0

我想要的是,通过身份验证的用户使用他们的凭据进行解锁,这样我们就会在AD日志中找到跟踪信息。如果我们使用的服务帐户像你建议那么它将是通用的 – 2014-12-02 22:33:37

0

在IIS中,单击您的网站,然后单击身份验证图标。确保禁用匿名身份验证并仅启用Windows身份验证。

+0

是的,我可以确认是这种情况 – 2014-12-03 19:25:31

+0

你是如何发送解锁或重置命令?也许发布一些代码? – 2014-12-03 22:53:27

+0

这里没有问题是重置密码代码(正如我之前说的那样在本地工作,但不在IIS上) – 2014-12-03 23:06:00