2013-10-02 41 views
1

与我的许多ServiceStack问题一样,我相信这会很容易。未设置AppHostBase实例

我有一个asp.net MCC4应用程序,我在其中使用ServiceStack进行身份验证。因为由ServiceStack客户端生成的Cookie不共享,我一直遵循这样的问题的答复来解决问题:

ServiceStack Session always null in MVC Controller

在我的客户我有这样的代码片段:

  var authService = AppHostBase.Resolve<AuthService>(); 
      authService.RequestContext = System.Web.HttpContext.Current.ToRequestContext(); 
      var AuthResponse = authService.Authenticate(new Auth 
      { 
       provider = "credentials", 
       UserName = user.user_id, 
       Password = user.password, 
       RememberMe = true 
      }); 


      if (AuthResponse.SessionId != null) 
      { 
       Session["IsAuthenticated"] = true; 
       Session["UserID"] = AuthResponse.UserName; 
       FormsAuthentication.SetAuthCookie(user.user_id, true); 
       return Redirect("/home"); 
      } 
      else 
      { 
       Session["IsAuthenticated"] = false; 
      } 

当我尝试和运行应用程序,我得到的错误:“AppHostBase未初始化

我可能会缺少什么?我提前道歉,因为我对ASP.net的一般经验不足。

更新

我应该指出,这仅仅是将使用ServiceStack API这是一个不同的项目的一部分MCV4客户端应用程序。

更新2

我认为这可能是我的SS的不完美理解的一部分,它将如何融入Web应用程序,如这一点。我相信我真的可以理解的是,这个ASP.net客户端如何通过ServiceStack API服务器上的现有会话进行备份。

+0

什么是你的控制器继承一个cache provider?此外,这个片段有什么方法? – mickfold

+0

继承自ControllerBase,片段来自“public ActionResult登录(UserModel用户)” – SeanH

回答

3

您需要配置mvc4环境下的应用平台,只需添加和运行APPHOST配置,并调用它whitin全球ASAX文件

在我的情况

我跑我的ServiceHost处于空白web应用程序但也可以为你工作mvc4。

protected void Application_Start(object sender, EventArgs e) 
    { 

     new AppServiceHost().Init(); 
     RouteTable.Routes.MapHubs(); 
    } 

在serviceStack应用:

public class AppServiceHost : AppHostBase 
    { 
     public AppServiceHost() 
      : base("Rest Service", typeof (AnyServiceYouHave).Assembly) 
     { 
      SetConfig(new EndpointHostConfig 
       { 
        //your configuration 
       }); 
     } 

     public override void Configure(Container container) 
     { 
      //Your configuration 
     } 
} 

编辑: 分享您的会话建立用户已经配置在服务栈

container.Register<ICacheClient>(new MemoryCacheClient()); //or any other 
+0

是的,没有初始化AppHost看起来像什么问题在这里。另外[MVC集成](https://github.com/ServiceStack/ServiceStack/wiki/Mvc-integration)文档提供了一些更多信息。 – mythz

+0

我们正在某处:D - 现在,我收到错误“无法解析类型ServiceStack.ServiceInterface.Auth.AuthService所需的依赖项。” – SeanH

+0

好像您的容器配置不正确,请随时关闭此问题并打开另一个有关您的新问题的信息。 –

相关问题