Fix: ASP.NET 4 Page on IIS 7 Misbehaves When Browser URL Doesn’t Include Default Page

After deploying an ASP.NET 4 application to the production server, data submitted in a form on the default page went nowhere. I discovered that the page worked normally if I included the name of the default document as in When I navigated to the site as the postback misbehaved to the extent that there was no SQL connection – as if it didn’t even try.

All this worked fine on the development server which is IIS 6. The production server is IIS 7.

The fix was to go into my site’s master page and set the action attribute to default.aspx in the form tag:

<form id="form1" action="default.aspx" runat="server">

There’s a detailed explanation  in the section “Event Handlers Might Not Be Not Raised in a Default Document in IIS 7 or IIS 7.5 Integrated Mode”  of the ASP.NET 4 Breaking Changes document.

Am I the only one who loses time on stuff like this?



  • I have not come across this yet! But as I do use some custom http modules it is worth remembering.

    Thanks for sharing! It could save me a lot of time in the future.

  • Thanks a lot :)
    It works

  • I tried this and it works except if the default document uses query strings. When there are query strings, they do not automatically get put into the "action" attribute, and then when you do a postback, it's posting back to "default.aspx" without the querystrings. So checking for a querystring value via something like Request.QueryString["value"] is null. I ended up setting the "action" manually like this:

    Page.Form.Action = Request.Url.PathAndQuery;

    This will include both default.aspx as well as any querystrings. It also includes the path, but that seems to work just as well.

Comments have been disabled for this content.