2

See update to this question at the bottom of the original message

I have a page, Default.aspx, that contains a dropdownlist with autopostback set to true and onselectedindexchanged set to a method in the code-behind. This issue is this:

  1. In ASP.NET 2.0, it works fine. (Displays the URL of the dropdown item you selected)
  2. In ASP.NET 4.0 Classic, it works fine.
  3. In ASP.NET 4.0 Integrated, it works fine if you go to the website using the filename, e.g. www.example.com/test/Default.aspx).
  4. In ASP.NET 4.0 Integrated, if you go to the website without the filename (e.g. www.example.com/test/), it does not work. Specifically, what it seems to do is go to the page as if for the first time and displays "You are in Page_Load, not on Postback"

Note: This page doesn't really exist at www.example.com, just so's you know.

I need it to work on ASP.NET 4.0 Integrated. Does anyone know what in the world is going on here?

I have created a simple page to demonstrate this:

Markup:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Test_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
 <asp:Panel ID="pSelectCourse" runat="server">
    Select Course:
    <asp:DropDownList ID="ddlNews" runat="server" AutoPostBack="True" 
        OnSelectedIndexChanged="ddlNews_SelectedIndexChanged">
        <asp:ListItem Text="-- Select a News Source --" Value="" ></asp:ListItem>
        <asp:ListItem Text="CNN" Value="http://www.cnn.com"></asp:ListItem>
        <asp:ListItem Text="New York Times" Value="http://www.nytimes.com"></asp:ListItem>
    </asp:DropDownList>
</asp:Panel>
</div>
</form>
</body>
</html>

Code-behind:

public partial class Test_Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            Response.Write("You are in Page_Load on Postback");
        else
            Response.Write("You are in Page_Load, not on Postback");
    }

    protected void ddlNews_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Write(ddlNews.SelectedValue);
    }
}

Update to question:

This issue is discussed at the ASP.NET 4 Breaking Changes page at http://asp.net/whitepapers/aspnet4/breaking-changes. This is the issue listed as: "Event Handlers Might Not Be Not Raised in a Default Document in IIS 7 or IIS 7.5 Integrated Mode" At the bottom of the issue are two solutions. The second is to explicitly set the action value on the form to the Default.aspx page. This works (try it in the code above to see) but is not particularly elegant and is a pain in the neck for several sites we have that have complex forms in default documents. I'd like a solution that I can apply globally so that "/" and "Default.aspx" are treated the same, as they were in 2.0. There is another solution above this on the Breaking Changes page, which I'm not understanding how to implement and which I'm hoping will provide this global solution:

Identify the HTTP module that is accessing the request's entity body during default document requests and determine whether it can be configured to run only for managed requests. In Integrated mode for both IIS 7 and IIS 7.5, HTTP modules can be marked to run only for managed requests by adding the following attribute to the module's system.webServer/modules entry:

precondition="managedHandler"

This setting disables the module for requests that IIS 7 and IIS 7.5 determine as not being managed requests. For default document requests, the first request is to an extensionless URL. Therefore, IIS does not run any managed modules that are marked with a precondition of managed Handler during initial request processing. As a result, managed modules will not accidentally read the entity body and thus the entity body is still available and is passed along to the child request and to the default document.

Does anyone have any ideas on how to implement this? I really don't know where to begin.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Laurie Dickinson
  • 796
  • 1
  • 10
  • 21
  • possible duplicate of [Event Handlers Might Not Be Not Raised in a Default Document in IIS 7 or IIS 7.5 Integrated Mode?](http://stackoverflow.com/questions/4673291/event-handlers-might-not-be-not-raised-in-a-default-document-in-iis-7-or-iis-7-5) – Tim B James Apr 23 '12 at 21:59
  • You are correct. I'm not thrilled with the solution (setting action explicitly to default.aspx) but it works. Thanks, and sorry for the duplicate post. – Laurie Dickinson Apr 24 '12 at 15:42

0 Answers0