AppHostBase比如不设置 [英] AppHostBase instance not set

查看:429
本文介绍了AppHostBase比如不设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像我的很多ServiceStack问题,我敢肯定,这将是pretty容易。

Like many of my ServiceStack questions, I'm sure this will be pretty easy.

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

I have an asp.net MCC4 application in which I am using ServiceStack for authentication. Because the cookies generated by the ServiceStack client aren't shared, I've followed the response in questions like this to resolve the issue:

<一个href=\"http://stackoverflow.com/questions/14835267/servicestack-session-always-null-in-mvc-controller\">ServiceStack会议始终处于空MVC控制器

在我的客户我有code这个片断:

In my client I have this snippet of code:

            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;
            }

当我尝试和运行应用程序,我得到的错误:

When I try and run the application, I get the error:

AppHostBase未初始化。

什么可能我会丢失?我提前道歉我一般缺乏经验与ASP.net。

What might I be missing? I apologize in advance for my inexperience with ASP.net in general.

更新

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

I should point out that this is only an MCV4 client application that will be using a ServiceStack API that is part of a different project.

更新2

我想这可能是我的SS不完美的理解,以及如何将融入一个Web应用程序,如这项工作的一部分。我相信我可能真的后,理解这个ASP.net的客户端是多么钩,备份与ServiceStack API服务器上的现有会话。

I think this might be a part of my not perfect understanding of SS and how it would fit into a web application such as this. I believe what I may really be after is understanding just how this ASP.net client can hook back up with an existing session on the ServiceStack API server.

推荐答案

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

you need to configure your appbase under the mvc4 context, just add and run your apphost configuration and call it whitin the global asax file

在我的情况我跑我的ServiceHost处于空白web应用程序,但是,可以为你工作mvc4为好。

in my case I'm running my servicehost in a blank web app but that could work for you mvc4 as well.

    protected void Application_Start(object sender, EventArgs e)
    {

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

在您的serviceStack应用:

in your serviceStack Application:

 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

这篇关于AppHostBase比如不设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆