2013-10-02 45 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

好像您的容器配置不正確,請隨時關閉此問題並打開另一個有關您的新問題的信息。 –

相關問題