与MVC控制器ServiceStack认证 [英] ServiceStack authentication with MVC Controllers
问题描述
我已经按照ServiceStack在SocialBootstrapAPi样本,但我不明白的重定向是如何接线。当我去到安全控制器是未经验证的我重定向回索引页面。我无法复制在自己的应用程序的行为。没发现这哪里配线完成 - 在SocialBootstrapApi的web.config无法找到他们。
I've followed the samples in SocialBootstrapAPi for ServiceStack but I don't get it how the redirects are wired up. When I go to the Secured controller being unauthenticated I get redirected back to the index page. I was unable to replicate the behaviour in my own application. Did not find where this wirings are done - can't find them in SocialBootstrapApi's web.config?
我从 ServiceStackController&LT继承; AuthUserSession>
,把 [授权]
我的基本控制器上。这是我的错误:
I've inherited from the ServiceStackController<AuthUserSession>
and put [Authenticate]
on my base controller. This is the error I get:
[NullReferenceException: Object reference not set to an instance of an object.]
ServiceStack.ServiceInterface.SessionExtensions.SessionAs(ICacheClient cache, IHttpRequest httpReq, IHttpResponse httpRes) +90
ServiceStack.Mvc.ServiceStackController.SessionAs() +64
ServiceStack.Mvc.ServiceStackController`1.get_UserSession() +36
ServiceStack.Mvc.ServiceStackController`1.get_AuthSession() +5
ServiceStack.Mvc.ExecuteServiceStackFiltersAttribute.OnActionExecuting(ActionExecutingContext filterContext) +97
这是我在AppHost.cs文件:
This is what I have in the AppHost.cs file:
//Enable Authentication
ConfigureAuth(container);
//Register In-Memory Cache provider.
//For Distributed Cache Providers Use: PooledRedisClientManager, BasicRedisClientManager or see: https://github.com/ServiceStack/ServiceStack/wiki/Caching
container.Register<ICacheClient>(new MemoryCacheClient());
container.Register<ISessionFactory>(c =>
new SessionFactory(c.Resolve<ICacheClient>()));
ConfigureAuth()类似于SocialBootstrapApi样品(不完全一样,但接近) - 我不认为有什么东西在这里失去了
ConfigureAuth() is similar to the SocialBootstrapApi sample (not exactly the same but close) - I don't think there's something missing here.
那么,这如何工作的?
推荐答案
推进评论一个答案,每个管理员的要求:
Promoting comment to an answer, per OPs request:
你设置你的IoC为你的MVC控制器? ControllerBuilder.Current.SetControllerFactory(新FunqControllerFactory(集装箱));
Did you set your IoC for your MVC controller? ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
这篇关于与MVC控制器ServiceStack认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!