3

我在 IIS 7.5 上运行 ServiceStack 应用程序,自定义 CredentialsAuthProvider 服务于/auth/credentials.

它在 Visual Studio 中运行良好,但是当我将它安装在生产服务器(也是 IIS 7.5)上时,它对所有对/auth/credentials. 服务 REST 端点没有任何问题,如果我将提供者的超类更改为 BasicAuthProvider,身份验证工作,但我想使用表单而不是基本身份验证。我怎样才能让它正确地服务于身份验证端点?

这就是我的 Web.config 的样子:

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

<configuration>
  <location path="auth">
    <system.web>
      <customErrors mode="Off"/>
      <httpHandlers>
        <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
      </httpHandlers>
    </system.web>
  </location>
  <location path="rest">
    <system.web>
      <httpHandlers>
        <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
      </httpHandlers>
    </system.web>

    <!-- Required for IIS 7.0 -->
    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true" />
      <validation validateIntegratedModeConfiguration="false" />
      <handlers>
        <add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
      </handlers>
    </system.webServer>
  </location>

  <!-- Required for MONO -->
  <system.web>
    <httpHandlers>
      <add path="rest*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
      <add path="auth*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
    </httpHandlers>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
        <httpErrors errorMode="DetailedLocalOnly">
            <remove statusCode="403" subStatusCode="-1" />
            <error statusCode="403" prefixLanguageFilePath="" path="https://nearme.solarcity.com" responseMode="Redirect" />
        </httpErrors>
    <!--<modules runAllManagedModulesForAllRequests="true">
      <remove name="WebDAVModule" />
    </modules>-->
    <!--uncomment this to stop IIS 7.5 from blocking PUT and DELETE-->
  </system.webServer>
</configuration>
4

1 回答 1

3

您在配置中做出了错误的假设。

您只能将 ServiceStack 托管在一个路径上,该路径可以是根路径*,也可以是通常按照约定的自定义路径,也/api可以/servicestack是您选择的任何名称。HelloWorld 教程显示了两个受支持选项的示例配置

通过使用 [Authenticate] 属性装饰 Request DTO 或 Service 来强制执行身份验证。如果您愿意,您还可以将属性添加到自定义基类,例如AuthenticatedServiceBase,这将确保所有子类也需要身份验证。

于 2012-09-07T04:39:47.183 回答