简体   繁体   中英

Click events not firing on default page of ASP.NET website unless default.aspx is in the URL

I have a website where if you launch the main page, either while debugging in Visual Studio or when published, it will not fire the click events of buttons unless you have the page explicitly declared in the URL.

ie on http://localhost:58599/Default.aspx they work, but http://localhost:58599/ they do not. Page_Load events are fired in both instances.

The page uses a master page and neither the click events on it nor on Default.aspx will work in this scenario.

What could be causing this problem? I can provide code if needed but I'm not sure which code would be relevant here.

Solution found on Postback doesn't work with aspx page as Default Document

I added the following code to my Global.asax page:

Private Sub Application_BeginRequest(sender As Object, e As EventArgs)
    Dim app = DirectCast(sender, HttpApplication)
    If app.Context.Request.Url.LocalPath.EndsWith("/") Then
        app.Context.RewritePath(String.Concat(app.Context.Request.Url.LocalPath, "default.aspx"))
    End If
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM