2

There is no simple ServiceStack sample as classic ASP.NET MVC. Both AppHarbor and SocialBootStrap api based on SinglePage Application. How can I implement classic Asp.net MVC application with Servicestack's Authentication.

I've added AuthService property to BaseController (Autowired). And then I got weird "object reference" exception while implemantation. ( AuthService line 135 base.RequestContext is null)

Why I'm getting this error? Or could anyone send simple usage. (Like Asp.net Mvc Membership Starter)

Oguz Karadenizli
  • 3,449
  • 6
  • 38
  • 73

1 Answers1

1

Services that make use of the RequestContext, needs to be the injected with the current Request Context, e.g:

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

This uses extension methods in SessionExtensions.cs.

You will also want to resolve any Services from the IOC - here's a good example of sharing functionality between ServiceStack and MVC.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • @ozz i am curious, how do you use the AuthService from BaseController to authorize access to action methods? I am trying the same with custom CredentialsAuthProvider but with no success. – ljubomir Jun 28 '12 at 12:37
  • I 've asked it also http://stackoverflow.com/questions/11236728/authentication-and-authorization-with-servicestack-mvc/11238758#11238758 – Oguz Karadenizli Jun 28 '12 at 15:14
  • Found the problem with my code: i was not setting session.IsAuthenticated = true, once the authentication was successful. I can confirm that [Authenticate] works pretty slick now. – ljubomir Jun 29 '12 at 10:15
  • 1
    This code does not work now.There is no ToRequest() or ToResponse extension. – Oguz Karadenizli Dec 19 '12 at 15:26
  • @ozz Doesn't work is different to you are unable to find it. Use ReSharper or `Ctrl+Shift+F` Search for `ToRequest(this` or ask someone else to do the search for you. Either way, finding references is a solved problem which have many solutions. – mythz Dec 20 '12 at 01:35