servicestack,C#,Authentication,Http Status Code 404,servicestack" /> servicestack,C#,Authentication,Http Status Code 404,servicestack" />

C# 在IIS 8上运行的自定义身份验证Servicestack服务对于未经身份验证的方法返回404

C# 在IIS 8上运行的自定义身份验证Servicestack服务对于未经身份验证的方法返回404,c#,authentication,http-status-code-404,servicestack,C#,Authentication,Http Status Code 404,servicestack,我正在IIS8集成管道(框架4.5)上运行ServiceStack服务web项目(非MVC项目) 现在,如果我的服务尚未通过身份验证,它将返回404。如果经过身份验证,它将正常运行。 我本以为是401。我还使用IIS Express对其进行了测试,并返回了相同的代码 请求/响应DTO: [Route("/common/init/{token}/{timestamp}")] public class InitRequest { public string Token { get; set;

我正在IIS8集成管道(框架4.5)上运行ServiceStack服务web项目(非MVC项目)

现在,如果我的服务尚未通过身份验证,它将返回404。如果经过身份验证,它将正常运行。 我本以为是401。我还使用IIS Express对其进行了测试,并返回了相同的代码

请求/响应DTO:

[Route("/common/init/{token}/{timestamp}")]
public class InitRequest
{
    public string Token { get; set; }
    public string TimeStamp { get; set; } //This also prevents an unwanted IE request caching
}

public class InitResponse
{
}
服务:

public class CommonService : Service
{

    [Authenticate]
    public object Get(InitRequest request)
    {
        ...
    }
 }
Web.config:

<system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
        <add path="*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
    </handlers>
</system.webServer>  
请求标头:

GET /GlonecoServices/login?      redirect=http%3a%2f%2flocalhost%2fGlonecoServices%2fcommon%2finit%2fsometoken%2f123456789 HTTP/1.1
User-Agent: Fiddler
Host: localhost
响应标题:

HTTP/1.1 404 Not Found
Cache-Control: private
Content-Type: text/plain; charset=utf-8
Vary: Accept
Server: Microsoft-IIS/8.5
X-Powered-By: ServiceStack/4,035 Win32NT/.NET
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 14 Jan 2015 18:22:20 GMT
Content-Length: 328

对于HTML客户端/用户代理(即Web浏览器),默认情况下,ServiceStack会自动将试图访问
[Authenticate]
受保护服务的未经身份验证的用户重定向到
/login
页面

注册AuthFeature插件时,可以更改
/login
页面约定,即:

Plugins.Add(new AuthFeature(...) {
    HtmlRedirect = "/customlogin"
});

您能否为返回404的请求提供原始HTTP请求/响应头?您可以从Chrome的WebInspector或Fiddler获取原始HTTP头。请通过更新此问题发布完整的HTTP请求和响应头,即不要在评论中发布它们。因此,如果我查看请求头(我没有),我似乎需要一些登录服务?我现在正在使用自定义路由(…/smsauthenticate/{mobilephonenumber}/{code})进行身份验证。刚刚添加了一个答案,按照惯例,它会重定向到
/login
,但在注册
AuthFeature
插件时,可以自定义重定向到您首选的登录页面。再次感谢(再次)您的快速帮助。
Plugins.Add(new AuthFeature(...) {
    HtmlRedirect = "/customlogin"
});