【问题标题】:windows authentication in ASP.NET application not working properly after hosting in IIS在 IIS 中托管后,ASP.NET 应用程序中的 Windows 身份验证无法正常工作
【发布时间】:2013-04-10 09:10:41
【问题描述】:

NET 应用程序使用 Windows 身份验证 该应用程序在我的本地解决方案中运行良好。但是当托管在 IIS 中时,它要求用户访问托管服务器。它没有从客户端机器获取用户凭据。

下面是我的 WEB.Config

<authentication mode="Windows">
        <!--<forms loginUrl="~/Account/Login.aspx" timeout="2880" />-->
</authentication>
<identity impersonate="false" />
<membership>
  <providers>
    <clear/>
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
         enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
         maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
         applicationName="/" />
  </providers>
</membership>

<profile>
  <providers>
    <clear/>
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
  </providers>
</profile>

<roleManager enabled="false">
  <providers>
    <clear/>
    <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
    <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
  </providers>
</roleManager>

<httpRuntime maxRequestLength="102400" />

获取用户名的ASP代码如下

string currentUser = HttpContext.Current.User.Identity.Name.ToLower();
                currentUser = currentUser.Replace("kmhp\\", "");
                SessionManager.Session.Current.LoggedInUserName = currentUser;
                dsValidateLogin = _grantAccessHandler.ValidateLogin(currentUser);

提前致谢

【问题讨论】:

    标签: c# asp.net .net authentication web


    【解决方案1】:

    这可能是客户端配置问题。使用 Internet Explorer,您必须确保客户端将 IIS 服务器识别为您的 Intranet 区域的一部分。默认情况下,只有 Intranet 区域允许转发用户凭据。 IE 有一些自动检测机制,但这并不总是有效。对于 Firefox,您需要将 IIS 服务器主机名添加到 about:config 中的配置值“network.automatic-ntlm-auth.trusted-uris”。否则,Firefox 也不会将凭据转发到您的服务器。

    【讨论】:

      【解决方案2】:

      您很可能需要拥有客户凭证。往下看

      <wsHttpBinding>
      <binding name="TransportSecurity">
      <security mode="Transport" />
         <transport clientCredentialType = "Windows" />
      </security>
      

      供参考:HttpBinding

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-16
        • 2020-07-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多