C# で記述され、Apache / mod_mono を使用して Linux マシンでホストされている API からデータ データを消費する asp.net mvc4 Web アプリケーションがあります。
クライアント アプリケーションは C#/asp.net で記述されています - 別の Web サーバー上で実行され、Linux / Apache / mod_mono でも実行されます。この場合、これらの詳細が重要かどうかはわかりませんが、背景が役立つ可能性があると考えました.
これに至るまでの質問: AppHostBase インスタンスが設定されていません - これがどのように組み合わされるかについて、かなり理解を深めるのに役立ちました。
私が今尋ねるべき適切な質問は次のとおりだと思います: servicestack (API サーバー上) でセッションを作成したら、どうすれば適切に再接続できますか?
前の質問の回答に従って、クライアント アプリケーションの認証コントローラーで次のコードを使用しました。
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
});
これにより、ResolutionException が返されます:
タイプ ServiceStack.ServiceInterface.Auth.AuthService の必要な依存関係を解決できませんでした。
クライアントをasp.netアプリケーション内から動作させることに関して、私が見逃しているかもしれない簡単なことはありますか?
質問があいまいすぎる場合は申し訳ありませんが、喜んでさらに情報を提供します。
更新:
これは AuthController です。前回の投稿以降、いくつか試してみました。
{
public partial class AuthController : BaseController
{
JsonServiceClient client = new ServiceStack.ServiceClient.Web.JsonServiceClient("<TheAPIurl>");
// GET: /Login/
public ActionResult login()
{
if (Session["IsAuthenticated"] != null)
{
ViewData["Result"] = Session["IsAuthenticated"];
}
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult login(UserModel user)
{
try
{
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;
Session["jsclient"] = client;
FormsAuthentication.SetAuthCookie(user.user_id, true);
return Redirect("/default");
}
else
{
Session["IsAuthenticated"] = false;
}
}
catch (Exception ex)
{
Session["IsAuthenticated"] = false;
}
return View();
}
protected override void ExecuteCore()
{
throw new NotImplementedException();
}
}
}