2012-06-27 46 views
2

AuthService有沒有簡單的ServiceStack樣品經典的ASP.NET MVC。基於SinglePage Application的AppHarbor和SocialBootStrap api。我如何使用Servicestack的身份驗證實現傳統的Asp.net MVC應用程序。使用ServiceStack與控制器和AuthorizeAttribute

我添加AuthService屬性BaseController(自動裝配Autowired)。然後,我在實現時遇到了奇怪的「對象引用」異常。 (AuthService線135 base.RequestContext爲null)

爲什麼我得到這個錯誤? 或者任何人都可以發送簡單的用法。 (就像Asp.net的MVC成員入門)

回答

1

服務,使使用的RequestContext的,需要被注入與當前請求上下文,e.g:

authService.RequestContext = new HttpRequestContext(
    HttpContext.Current.Request.ToRequest(), 
    HttpContext.Current.Response.ToResponse(), 
    null 
); 

它使用擴展方法在SessionExtensions.cs

您還需要解決來自國際奧委會的任何服務 - 這裏有sharing functionality between ServiceStack and MVC一個很好的例子。

+0

BaseController https://gist.github.com/3007664 – ozz

+0

@ozz我很好奇的最終狀態,你怎麼用從BaseController的AuthService授權訪問的操作方法?我正在嘗試與自定義CredentialsAuthProvider相同,但沒有成功。 – ljubomir

+0

我已經問這也http://stackoverflow.com/questions/11236728/authentication-and-authorization-with-servicestack-mvc/11238758#11238758 – ozz

相關問題