2

I have a .net site set up that runs fine as long as you specify the full filename including .aspx extension on the page. As you try and run a default page without the specifiying default.aspx then a postback will not fire.

e.g.

http://www.site.com/ (postback does not work)

http://www.site.com/default.aspx (postback works)

http://www.site.com/directory (postback does not work)

http://www.site.com/directory/default.aspx (postback works)

I've never had this problem before on a .net website so struggling to understand what the problem is. I've checked most basic things, i.e. ensuring default.aspx is a default page etc. checking my web.config file against a site that is working properly etc.

I still don't understand why this behaviour is occurring. Any ideas?

jrummell
  • 42,637
  • 17
  • 112
  • 171
sw1sh
  • 93
  • 1
  • 6
  • Please show your form. Did you set the `action` attribute? – jrummell Jun 12 '12 at 16:39
  • Is the site running on IIS or Visual Studio integrqted web server? – Marian Ban Jun 12 '12 at 16:39
  • 4
    A similar issue is described here: http://stackoverflow.com/questions/7228344/postback-doesnt-work-with-aspx-page-as-default-document. There are also some solution suggestions described. Take a look at it :). – Lukasz M Jun 12 '12 at 16:39

2 Answers2

2

Lucas, thanks for sharing that answer.

Indeed the form action tag was empty in cases where the default.aspx had not been explicitly provided in the URL.

Adding the following code to global.asax has solved the problem:

void Application_BeginRequest(object sender, EventArgs e)
{
    var app = (HttpApplication)sender;
    if (app.Context.Request.Url.LocalPath.EndsWith("/"))
    {
    app.Context.RewritePath(
             string.Concat(app.Context.Request.Url.LocalPath, "default.aspx"));
    }
}
sw1sh
  • 93
  • 1
  • 6
1

I had this problem with one site and changed the Application Pool type to Classic. This fixed the problem.

Alan
  • 11
  • 1