如何保证HTTPContext有价值?

发布于 2024-08-06 13:40:13 字数 3279 浏览 5 评论 0原文

我正在构建 MVC Storefront 的一个版本。我有两个主题,一个是标准 ui,另一个是管理 ui。我有一些 HTML Helper 方法,它们将 .ascx 文件传递​​到 .aspx 文件,就像示例一样,但没有插件。所有的东西都适用于默认主题,但它们都不适用于管理主题。当 Html.SimpleActivityTypeList() 触发时,我总是遇到相同的错误。 Html.RenderPartial(“AdminLeftNav”) 将始终工作正常。

<asp:Content ID="Content3" ContentPlaceHolderID="NavContent" runat="server">
    <% Html.SimpleActivityTypeList(); %>
    <% Html.RenderPartial("AdminLeftNav"); %>
</asp:Content>

我已将如下方法添加到扩展类中。

public static void SimpleActivityTypeList(this HtmlHelper helper)
    {
        helper.RenderAction<CatalogController>(x => x.SimpleActivityTypeList());
     }

正如我所说,这在默认主题中效果很好。 请帮忙?

Stack Trace: 


[ArgumentNullException: Value cannot be null.
Parameter name: httpContext]
   System.Web.Routing.RequestContext..ctor(HttpContextBase httpContext, RouteData routeData) +85
   Microsoft.Web.Mvc.ViewExtensions.RenderRoute(HtmlHelper helper, RouteValueDictionary values) +367
   Microsoft.Web.Mvc.ViewExtensions.RenderAction(HtmlHelper helper, Expression`1 action) +113
   GrandGuide.Web.CMSExtensions.SimpleActivityTypeList(HtmlHelper helper) in C:\S3_Depot\S3_Dev\GrandGuide\GrandGuide.Web\Infrastructure\Helpers\CMSExtensions.cs:55
   ASP.views_themes_admin_index_aspx.__RenderContent3(HtmlTextWriter __w, Control parameterContainer) in c:\S3_Depot\S3_Dev\GrandGuide\GrandGuide.Web\Views\Themes\Admin\Index.aspx:7
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   ASP.views_themes_admin_theme_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\S3_Depot\S3_Dev\GrandGuide\GrandGuide.Web\Views\Themes\Admin\Theme.Master:33
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29
   System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +71
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

I am building a version of the MVC Storefront. I have two themes, one is the standard ui, and the other is the admin ui. I have some HTML Helper methods, which deliver .ascx files to the .aspx files just like the example, but without plug-ins. All the stuff works on the default theme, but none of it works in the admin theme. I always get the same error when the Html.SimpleActivityTypeList() fires. The Html.RenderPartial(“AdminLeftNav”) will always work fine.

<asp:Content ID="Content3" ContentPlaceHolderID="NavContent" runat="server">
    <% Html.SimpleActivityTypeList(); %>
    <% Html.RenderPartial("AdminLeftNav"); %>
</asp:Content>

I have added a method as below to an extension class.

public static void SimpleActivityTypeList(this HtmlHelper helper)
    {
        helper.RenderAction<CatalogController>(x => x.SimpleActivityTypeList());
     }

And as I said this works fine in the default theme.
Please Help?

Stack Trace: 


[ArgumentNullException: Value cannot be null.
Parameter name: httpContext]
   System.Web.Routing.RequestContext..ctor(HttpContextBase httpContext, RouteData routeData) +85
   Microsoft.Web.Mvc.ViewExtensions.RenderRoute(HtmlHelper helper, RouteValueDictionary values) +367
   Microsoft.Web.Mvc.ViewExtensions.RenderAction(HtmlHelper helper, Expression`1 action) +113
   GrandGuide.Web.CMSExtensions.SimpleActivityTypeList(HtmlHelper helper) in C:\S3_Depot\S3_Dev\GrandGuide\GrandGuide.Web\Infrastructure\Helpers\CMSExtensions.cs:55
   ASP.views_themes_admin_index_aspx.__RenderContent3(HtmlTextWriter __w, Control parameterContainer) in c:\S3_Depot\S3_Dev\GrandGuide\GrandGuide.Web\Views\Themes\Admin\Index.aspx:7
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   ASP.views_themes_admin_theme_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\S3_Depot\S3_Dev\GrandGuide\GrandGuide.Web\Views\Themes\Admin\Theme.Master:33
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29
   System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +71
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡水深流 2024-08-13 13:40:13

更多信息会有帮助。过去,我使用过:

if (null != HttpContext)

或者,如果您要访问上下文中的某些内容,例如会话变量:

if (null != HttpContext.Current.Session["my_var"])

More info would help. In the past, I've used:

if (null != HttpContext)

or, if you're accessing something in the context such as a Session Variable:

if (null != HttpContext.Current.Session["my_var"])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文