首页 > 解决方案 > ServiceStack api/auth/credentials 在前端迁移时返回 404

问题描述

我正在将我的前端更改为 React,因此我使用 VS2015 开始了一个新项目。我已经用我的旧 API 服务配置了 ServiceStack。一切正常,除了一个:api/auth/credentials。

当我尝试发送 POST 时收到 404。

我的Configure有:

public MyApphost() : base("My web services", typeof(MyApphost).Assembly) {}

和:

(在之前对插件的调用中)

IoC.Container.Register<IDbConnectionFactory>(c => new OrmLiteConnectionFactory(Dvtrck.Configuration.Manager.Current.Dsn, Dvtrck.Services.OrmLiteDialects.PostgreSQLDialectProviderLowerCase.Instance));

...(一些代码和)

Plugins.Add(new AuthFeature(() =>
    new UserSession(),
    new IAuthProvider[] {
        new CustomAuthProvider(), // CustomAuthProvider : CredentialsAuthProvider
    }));

我的 web.config 有:

<location path="api">
    <system.web>
        <httpHandlers>
            <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
        </httpHandlers>
    </system.web>
    <!-- ServiceStack: Required for IIS7 -->
    <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>

我已经检查过类似的问题,但我的情况不同。即使我在添加时也没有错误AuthFeature。我不明白为什么在我的旧项目中运行良好。

标签: c#servicestackcredentials

解决方案


您还需要配置

SetConfig(new HostConfig { HandlerFactoryPath = "api" });

推荐阅读