SharpArch.Domain.PreconditionException:'尚未配置ISessionStorage'

时间:2018-02-09 04:18:44

标签: asp.net nhibernate asp.net-identity

我尝试使用hibernate构建ASP.NET Identity项目 SharpArch.Domain.PreconditionException:'尚未配置ISessionStorage' https://github.com/Streamc/IdHiber

我从https://github.com/nhibernate/NHibernate.AspNet.Identity/tree/master/source/NHibernate.AspNet.Web项目借用代码 我制作了新项目并添加了一些文件。 我制作了Register.html并在大约.cshtml文件中粘贴代码

@model IdHiber.Models.RegisterViewModel
@{
    ViewBag.Title = "Register";
}
<h2>@ViewBag.Title.</h2>
@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
    @Html.AntiForgeryToken()
    <h4>Create a new account.</h4>
    <hr />
    @Html.ValidationSummary()
    <div class="form-group">
        @Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
        <div class="col-md-10">
            @Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
        <div class="col-md-10">
            @Html.PasswordFor(m => m.Password, new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" })
        <div class="col-md-10">
            @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" class="btn btn-default" value="Register" />
        </div>
    </div>
}

它显示错误:

    public class AccountController : Controller
    {
        public AccountController()
            : this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(NHibernateSession.Current)))
        {
        }
...
}

我保留了一个mysqlite数据库。我能做些什么

[PreconditionException: An ISessionStorage has not been configured]
   SharpArch.Domain.Check.Require(Boolean assertion, String message) in c:\projects\milesibastos\Sharp-Architecture\Solutions\SharpArch.Domain\DesignByContract\Check.cs:296
   SharpArch.NHibernate.NHibernateSession.CurrentFor(String factoryKey) in c:\projects\milesibastos\Sharp-Architecture\Solutions\SharpArch.NHibernate\NHibernateSession.cs:117
   SharpArch.NHibernate.NHibernateSession.get_Current() in c:\projects\milesibastos\Sharp-Architecture\Solutions\SharpArch.NHibernate\NHibernateSession.cs:80
   IdHiber.Controllers.AccountController..ctor() in C:\Users\userx\source\repos\IdHiber\IdHiber\Controllers\AccountController.cs:16

[TargetInvocationException: 
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +119
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +247
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
   System.Activator.CreateInstance(Type type) +11
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +55

[InvalidOperationException: An error occurred when trying to create a controller of type 'IdHiber.Controllers.AccountController'. Make sure that the controller has a parameterless public constructor.]
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +178
   System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +76
   System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +88
   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +194
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +50
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +103
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

但我没有c:\projects\milesibastos文件夹!

我该怎么办?

1 个答案:

答案 0 :(得分:1)

我不知道您是否已解决此问题,但我遇到了同样的问题,并通过修改startup.cs使其包含以下内容来解决了该问题

public partial class Startup
{
    public void Configuration(IAppBuilder app)
    {
        ConfigureAuth(app);
        ConfigureData();
    }

    private static void ConfigureData()
    {
        var storage = new WebSessionStorage(System.Web.HttpContext.Current.ApplicationInstance);
        DataConfig.Configure(storage);
    }
}

还要确保您的bin文件夹中有一个hibernate.cfg文件。我希望这可以节省一些时间!