2

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" />

1 Answers1

1

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.

Ahmad Ibrahim
  • 1,915
  • 2
  • 15
  • 32