简体   繁体   English

除非URL中包含default.aspx,否则单击事件不会在ASP.NET网站的默认页面上触发

[英]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. 我有一个网站,如果您在Visual Studio中调试或发布时启动主页,则除非您在URL中明确声明了该页面,否则它将不会触发按钮的单击事件。

ie on http://localhost:58599/Default.aspx they work, but http://localhost:58599/ they do not. 即在http:// localhost:58599 / Default.aspx上它们可以工作,但在http:// localhost:58599 /上却不能。 Page_Load events are fired in both instances. 在这两种情况下都会触发Page_Load事件。

The page uses a master page and neither the click events on it nor on Default.aspx will work in this scenario. 该页面使用一个母版页,在该页上或Default.aspx上的单击事件在这种情况下均不起作用。

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 回发中找到的解决方案不适用于aspx页面作为默认文档

I added the following code to my Global.asax page: 我在Global.asax页面中添加了以下代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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