我正在关注ServiceStack的在线课程。大多数示例代码都是基于3.x的,但很容易转换为4.05。然而,授权给我一个我无法解决的问题,我在global.asax.cs中配置身份验证,如下所示:
public class ProteinTrackerAppHost : AppHostBase
{
public ProteinTrackerAppHost() : base("Protein Tracker",typeof(EntryService).Assembly) {}
public override void Configure(Container container)
{
Plugins.Add(new AuthFeature(
() => new AuthUserSession(),
new IAuthProvider[] { new BasicAuthProvider() }));
container.Register<ICacheClient>(new MemoryCacheClient());
var userRepository = new InMemoryAuthRepository();
container.Register<IUserAuthRepository>(userRepository);
string hash;
string salt;
new SaltedHash().GetHashAndSaltString("bhuijn", out hash, out salt);
userRepository.CreateUserAuth(new UserAuth
{
Id = 1,
DisplayName = "JoeUser",
Email = "joe@user.com",
UserName = "martin",
FirstName = "joe",
LastName = "User",
PasswordHash = hash,
Salt = salt
}, "bhuijn");
}
这个编译并运行正常,然后我使用以下代码从客户端连接:
var client = new JsonServiceClient("http://localhost:49172/")
{ UserName = "martin", Password = "bhuijn" };
每个被调用的服务都可以正常运行,除了那些需要身份验证的服务,如
[Route("/status")]
[Authenticate]
public class StatusQuery : IReturn<StatusResponse>
{
哪个给我一个例外“未找到”。
赞赏任何想法
堆栈追踪:
A first chance exception of type 'System.Net.WebException' occurred in System.dll
A first chance exception of type 'ServiceStack.WebServiceException' occurred in
ServiceStack.Client.dll
Not Found
at ServiceStack.ServiceClientBase.ThrowWebServiceException[TResponse](Exception ex,
String requestUri)
at ServiceStack.ServiceClientBase.ThrowResponseTypeException[TResponse](Object request,
Exception ex, String requestUri)
at ServiceStack.ServiceClientBase.HandleResponseException[TResponse](Exception ex,
Object request, String requestUri, Func`1 createWebRequest, Func`2 getResponse,
TResponse& response)
at ServiceStack.ServiceClientBase.Send[TResponse](String httpMethod, String
relativeOrAbsoluteUrl, Object request)
at ServiceStack.ServiceClientBase.Post[TResponse](String relativeOrAbsoluteUrl, Object
requestDto)
at ServiceStack.ServiceClientBase.Post[TResponse](IReturn`1 requestDto)
at Consumer.Program.Main(String[] args) in
c:\projects\servicestack1\Consumer\Program.cs:line 29
responseBody是:
Handler for Request not found:
Request.HttpMethod: GET
Request.PathInfo: /login.aspx
Request.QueryString: ReturnUrl=%2fstatus
Request.RawUrl: /login.aspx?ReturnUrl=%2fstatus
基本上web.conf看起来像这样:
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<!-- preCondition="IntegratedMode" -->
<add path="*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" resourceType="Unspecified" allowPathInfo="true"/>
</handlers>
答案 0 :(得分:0)
您的回复正文信息表明您正被重定向到“login.aspx”页面,该页面可能不存在?因此,它找不到您的登录页面,并且给您一个未找到的错误。这让我假设您在web.config中配置了表单身份验证?查找该设置并注释掉form-authentication。