HttpContext.IsPostNotification是假的时,编译调试是假的 [英] HttpContext.IsPostNotification is false when Compilation debug is false

查看:358
本文介绍了HttpContext.IsPostNotification是假的时,编译调试是假的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MVC项目HttpContext.IsPostNotification是假的时



 <编译调试=假targetFramework =4.5/ > 



HttpContext.IsPostNotification为真时



 <编译调试=真targetFramework =4.5/> 



我的控制器HomeController.cs

 使用系统; 
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.Mvc;

命名空间Learning.Controllers
{
公共类HomeController的:控制器
{
公众的ActionResult指数()
{
ViewBag .Message =修改此模板,以启动你的ASP.NET MVC应用程序。
ViewBag.PostNotification = HttpContext.IsPostNotification;
返回查看();
}
}
}



我的视图Index.cshtml

  @ {
ViewBag.Title =主页;
}
@ ViewBag.PostNotification



MVC应用程序在Windows Server上运行(开发在Windows 7中),IIS7集成管道模式。



我想将我的应用程序来生产,但HttpContext.IsPostnotification当设置为

$ b $是假的b

 <编译调试=假targetFramework =4.5/> 


解决方案

使用 HttpContext.IsPostNotification 中的操作方法是没有意义的。在 IsPostNotification 是为了与 HttpContext.CurrentNotification 中的之间的主要的和区分的发布 HttpApplication的活动

 公共类MvcApplication:System.Web.HttpApplication 
{
保护无效的Application_Start()
{

}

//主事件处理
无效Application_AcquireRequestState(对象发件人,EventArgs五)
{
//Context.CurrentNotification是的AcquireRequestState
//Context.IsPostNotification为假
}

//张贴的事件处理函数
无效Application_PostAcquireRequestState(对象发件人,EventArgs五)
{
//Context.CurrentNotification是的AcquireRequestState
//Context.IsPostNotification为真
}


}

我不知道你再努力实现,但如果你想检测的HttpApplication 事件后,那么你可以把你的代码在事件处理程序,除非该事件处理程序与其他事件的注册,那么你就需要使用 CurrentNotification IsPostNotification 来检测其触发的事件处理程序。


In MVC project HttpContext.IsPostNotification is false when

<compilation debug="false" targetFramework="4.5" />

HttpContext.IsPostNotification is true when

<compilation debug="true" targetFramework="4.5" />

My controller "HomeController.cs"

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Learning.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
            ViewBag.PostNotification = HttpContext.IsPostNotification;
            return View();
        }
    }
}

My View "Index.cshtml"

@{
    ViewBag.Title = "Home Page";
}
@ViewBag.PostNotification

MVC application runs in Windows Server (developing in Windows 7), IIS7 Integrated Pipeline mode.

I want to move my application to production, but HttpContext.IsPostnotification is false when set to

<compilation debug="false" targetFramework="4.5" />

解决方案

Using HttpContext.IsPostNotification in an action method is meaningless. The IsPostNotification is meant to be used with HttpContext.CurrentNotification to distinguish between Main and Post HttpApplication Events.

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        ...
    }

    // Main Event handler
    void Application_AcquireRequestState(object sender, EventArgs e)
    {
        //Context.CurrentNotification Is "AcquireRequestState"
        //Context.IsPostNotification Is "False"
    }

    // Post Event handler
    void Application_PostAcquireRequestState(object sender, EventArgs e)
    {
        //Context.CurrentNotification Is "AcquireRequestState"
        //Context.IsPostNotification Is "True"
    }

    ...
}

I'm not sure what you're trying to achieve, but if you want to detect an HttpApplication event completion, then you can just put your code in the event handler, unless this event handler is registered with other events, then you will need to use CurrentNotification and IsPostNotification to detect which event fired the handler.

这篇关于HttpContext.IsPostNotification是假的时,编译调试是假的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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