【问题标题】:Windows Azure basic authentication doesn't work in the cloud?Windows Azure 基本身份验证在云中不起作用?
【发布时间】:2012-04-13 11:17:49
【问题描述】:

我正在使用肥皂 (wcf) 构建服务。我想用一个密码和用户名让我的端点更加安全。当我尝试添加以下配置时,Windows Azure 会抛出以下错误:

错误:此配置部分不能用于此路径。当该部分锁定在父级别时会发生这种情况。默认情况下锁定 (overrideModeDefault="Deny"),或者由具有 overrideMode="Deny" 或旧版 allowOverride="false" 的位置标记显式设置。

行代码是: 在本地测试时,我必须在我的 IIS 中进行更改,但显然我无法在 Windows Azure 平台上进行调整?

我想做的就是使用自己的密码和用户名进行访问。是

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.diagnostics>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </trace>
  </system.diagnostics>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <customErrors mode="Off"/>
  </system.web>

  <system.serviceModel>

    <behaviors>
      <serviceBehaviors>
        <behavior name="credsBehavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata externalMetadataLocation="external metadata location" />

          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="WCFServiceWebRole.CustomUserNameValidator, WCFServiceWebRole, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="ServiceEndpointBehavior">
          <schemaValidator validateRequest="True" validateReply="False">
            <schemas>
              <add location="schemalocation" />
            </schemas>
          </schemaValidator>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false" />

    <extensions>
      <behaviorExtensions>
        <add name="schemaValidator" type="WCFServiceWebRole.Validation.SchemaValidationBehaviorExtensionElement, WCFServiceWebRole, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
      </behaviorExtensions>
    </extensions>

    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpsBinding_CvServiceInterface" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" receiveTimeout="01:00:00" openTimeout="01:00:00" closeTimeout="01:00:00" sendTimeout="01:00:00">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

          <security mode="Transport">
              <transport clientCredentialType="Basic"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

    <services>
      <service name="WCFServiceWebRole.CvService" behaviorConfiguration="credsBehavior">
        <endpoint address="myendpoint" behaviorConfiguration="ServiceEndpointBehavior" binding="basicHttpBinding" bindingConfiguration="BasicHttpsBinding_CvServiceInterface" contract="ICvService" />
      </service>
    </services>

  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true" />

    <security>
      <authentication>
        <basicAuthentication enabled="true"/>
      </authentication>
    </security>
  </system.webServer>
</configuration>

<!--<system.webServer>
  <security>
    <authentication>
      <anonymousAuthentication enabled="false" />
      <basicAuthentication enabled="true" />
    </authentication>
  </security>
</system.webServer>-->

杰伦

【问题讨论】:

    标签: wcf azure authorization


    【解决方案1】:

    默认情况下,基本身份验证在 Windows Azure Web 角色中不可用。

    您需要创建 2 个启动脚本:

    用于安装基本身份验证的 Powershell 脚本

    Import-Module ServerManager
    Add-WindowsFeature Web-Basic-Auth
    

    注意:这需要 Windows Server 2008 R2 中包含的 PowerShell 2.0(您需要将 osFamily 设置为 2 以获取 Windows Server 2008 R2:http://msdn.microsoft.com/en-us/library/windowsazure/ee758710.aspx

    将激活基本身份验证的 Bat 文件

    %windir%\system32\inetsrv\appcmd set config /section:basicAuthentication /enabled:true  
    

    问题

    为什么您甚至需要基本身份验证?如果我错了,请纠正我,但 WCF 中的用户名/密码身份验证应该在没有 IIS 的情况下工作,所以我不明白为什么它需要基本身份验证才能工作。

    【讨论】:

    • 就像我说的,当我在 Windows Azure(使用 IIS)上托管我的服务时,使用基本身份验证时会出错。 (原因是,就像您之前提到的,基本身份验证未启用)。如果您知道我的问题的其他方法或解决方案,请成为我的客人。我只需要客户端填写用户名和密码来验证服务器端的用户名和密码。我对这件事比较陌生,所以
    • 您可以从 web.config 中删除安全元素,这是导致问题的原因。安全性存在于 WCF 基础结构中。按照本指南使用自定义用户名/密码身份验证:blogs.msdn.com/b/pedram/archive/2007/10/05/…
    【解决方案2】:

    就像 Sandrino 提到的,我不需要 basicauth 来使用自定义用户名和密码获得授权和身份验证。

    代替:

    <security mode="Transport">
    <transport clientCredentialType="Basic"/>
    </security>
    

    我必须这样做:

      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="None"/>
        <message clientCredentialType="UserName" />
      </security>
    

    在客户端:

        ServiceReference1.CvServiceInterfaceClient cl = new ServiceReference1.CvServiceInterfaceClient();
        ClientCredentials creds = new ClientCredentials();
    
        creds.UserName.UserName = "username";
        creds.UserName.Password = "password";
        var defaultCredentials = cl.Endpoint.Behaviors.Find<ClientCredentials>();
        cl.Endpoint.Behaviors.Remove(defaultCredentials);
        cl.Endpoint.Behaviors.Add(creds);
    

    杰伦

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-06
      • 2014-01-22
      • 2016-01-11
      • 2020-12-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多