gpt4 book ai didi

asp.net - 如何确定从哪个MasterPage生成了错误?

转载 作者:行者123 更新时间:2023-12-03 07:54:39 27 4
gpt4 key购买 nike

我们有一个大型的ASP WebForms应用程序,我正在尝试使错误页面看起来更好并且更有帮助。我们有几个MasterPage,其中一个用于在通过JavaScript打开的模式窗口中的iframe中显示内容。现在,如果在这些模式页面之一中发生错误,则模式iframe将重定向到我们的~/Error.aspx页面,该页面包含正常的网站设计-在网站设计顶部的模式内。看起来很笨。

我想做的是确定生成错误的页面的母版,然后更改“错误”页面的母版,以便它不会从iframe内部重复设计。这可能吗?

最佳答案

经过大量调试后,我似乎找到了一种在VB中完成我想做的事情的方法,尽管它有点笨拙...

Public Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
'Attempt to determine if this error came from a page displayed within a modal
Dim page = TryCast(HttpContext.Current.CurrentHandler, _BasePage)
If page IsNot Nothing Then
Dim masterPageFile As String = page.MasterPageFile
'The best we can to here is to find the masterpage and see if it
'contains the string "modal" since that's normally how we name these things
If Not String.IsNullOrWhiteSpace(masterPageFile) AndAlso masterPageFile.Contains("modal", StringComparison.OrdinalIgnoreCase) Then
'==============
'We did it!!!
'==============
End If
Else
'Either `HttpContext.Current.CurrentHandler` or `Page` is `Nothing`, so this might be a 404 or other error.
'Let's see if there are other ways to determine if we are in a modal.

Dim pathToAttemptedFile = HttpContext.Current.Request.Path
Dim referrerUrl = HttpContext.Current.Request.UrlReferrer.AbsolutePath

If (Not String.IsNullOrWhiteSpace(pathToAttemptedFile) AndAlso pathToAttemptedFile.Contains(tokenInUrlPath, StringComparison.OrdinalIgnoreCase)) OrElse
(Not String.IsNullOrWhiteSpace(referrerUrl) AndAlso referrerUrl.Contains(tokenInUrlPath, StringComparison.OrdinalIgnoreCase)) Then
'==============
'We did it!!!
'==============
End If
End If
End Sub

关于asp.net - 如何确定从哪个MasterPage生成了错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26106703/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com