Umbraco

时间:2017-04-22 10:07:53

标签: c# asp.net-mvc umbraco umbraco7

我正在使用Umbraco 7.5.7作为我的应用程序当我点击CMS中的内容项时它会向我显示此错误,我已经提供了下面的代码,可以帮助我解决这个问题。 在访问内容和投掷时,Umbraco CMS中的HttpContext.Current.Session和UmbracoContext.Current.HttpContext.Session始终为null 从服务器收到错误 - "值不能为空。参数名称:httpSessionState" cms UI上的错误

IManageState.cs

public interface IManageState
{
void SetValue(string key, object data);
bool HasKey(string key);
T GetValue<T>(string key);
bool SessionIdExists();
}

SessionContext.cs

protected readonly IManageState SessionManager;
public SessionContext()
{
     SessionManager = new HttpSessionManager();
}

HttpSessionManager.cs

public class HttpSessionManager : IManageState
{

private readonly HttpSessionStateBase _session;
public HttpSessionManager()
{
}
public HttpSessionManager(HttpSessionStateBase session)
{
    _session = session;
}
public HttpSessionStateBase Session
{
    get { return _session ?? new HttpSessionStateWrapper(HttpContext.Current.Session); }//getting null here for HttpContext.Current.Session
}
public void SetValue(string key, object data)
{
    Session[key] = data;
}
public bool HasKey(string key)
{
    return Session[key] != null;
}
public T GetValue<T>(string key)
{
    return HasKey(key) ? (T)Session[key] : default(T);
}
public bool SessionIdExists()
{
    if (HttpContext.Current.Session == null)
    {
        return false;
    }
    string cookieHeader = HttpContext.Current.Request.Headers[GenericConstants.Cookie];
    return !string.IsNullOrEmpty(cookieHeader)
           && cookieHeader.IndexOf(GenericConstants.AuthorizationCode, StringComparison.OrdinalIgnoreCase) >= 0
           && HttpContext.Current.Request.Cookies[GenericConstants.DOTNETSESSIONID] != null
           && Session[GenericConstants.AuthorizationCode] != null
           && HttpContext.Current.Request.Cookies[GenericConstants.AuthorizationCode] == Session[GenericConstants.AuthorizationCode];
}
}

我也试过下面的代码,我换了这行

get { return _session ?? new HttpSessionStateWrapper(HttpContext.Current.Session); }

get { return _session != null ? _session : HttpContext.Current.Session != null ? new HttpSessionStateWrapper(HttpContext.Current.Session):  UmbracoContext.Current.HttpContext.Session ; }

栈跟踪

at System.Web.HttpSessionStateWrapper..ctor(HttpSessionState httpSessionState)
   at MyProject.Infrastructure.Services.HttpSessionManager.get_Session() in D:\MyProject\MyProject.Infrastructure\Services\HttpSessionManager.cs:line 50
   at MyProject.Infrastructure.Services.HttpSessionManager.HasKey(String key) in D:\MyProject\MyProject.Infrastructure\Services\HttpSessionManager.cs:line 74
   at MyProject.Infrastructure.Services.HttpSessionManager.GetValue[T](String key) in D:\MyProject\MyProject.Infrastructure\Services\HttpSessionManager.cs:line 123
   at MyProject.Web.Http.SessionContext.get_IsAuthenticated() in D:\MyProject\MyProject.Web\Http\SessionContext.cs:line 125
   at ASP._Page_Views_MacroPartials_Dashboard_cshtml.Execute() in d:\MyProject\MyProject.Web\Views\MacroPartials\Dashboard.cshtml:line 7
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
   at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
   at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer)
   at Umbraco.Web.Mvc.ControllerExtensions.RenderViewResultAsString(ControllerBase controller, ViewResultBase viewResult)
   at Umbraco.Web.Macros.PartialViewMacroEngine.Execute(MacroModel macro, IPublishedContent content)
   at Umbraco.Web.Macros.PartialViewMacroEngine.Execute(MacroModel macro, INode node)
   at umbraco.macro.LoadPartialViewMacro(MacroModel macro)
   at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
   at Umbraco.Web.UmbracoComponentRenderer.RenderMacro(macro m, IDictionary`2 parameters, page umbracoPage)
   at Umbraco.Web.Editors.MacroController.GetMacroResultAsHtml(String macroAlias, Int32 pageId, IDictionary`2 macroParams)
   at Umbraco.Web.Editors.MacroController.GetMacroResultAsHtmlForEditor(MacroParameterModel model)
   at lambda_method(Closure , Object , Object[] )
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()

0 个答案:

没有答案