locked
Creating a Intermediate html page in the Global ASAX for redirection. Is it a good practice? RRS feed

  • Question

  • User1555919309 posted

    I put a Server.Transfer to Application_Error of Global.asax. If there is any error it redirects to custom error page. However, after it is transferred to custom error page, I found the search bar function on the custom error page stopped working, it loads on the same page if I click search button. It is supposed to go to search.aspx next and show the search result on that page. 

    So Instead of directly server.trasfer to custom404 page, we created an intermediate html page which redirects to the custom error page.  (IntermediateRedirect.html). Then the search button worked. 

    * I cannot directly use response.redirect in the global.asax because I need to record detailed error info in the IIS log. If directly redirecting to custom error page, the search function works but I cannot have enough IIS log information (for example: I want IIS log to record the page name which is before hitting error page). 

    Before: Global.asax -> Server Transfer -> Custom Error Page (Search function on this page is broken.)

    After: Global.asax -> Server Transfer -> Intermediate HTML page -> Redirect -> Custom Error Page (Search function works by doing this)

    Do you think it is a good practice? Can you think any disadvantages or any harms to application for using this? I tried several methods but it seems to be the only solution for me. 

    Example:

    Global.asax

     Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
            Try
                If serverError IsNot Nothing Then
                        Server.ClearError()
                        Server.Transfer("/IntermediateRedirect.html")

                End If
            Catch
                ' redirect to a static htm page if any exceptions happen
                Server.Transfer("/404.htm")
            End Try   

    End Sub

    IntermediateRedirect.html

        <script type="text/javascript">
            window.onload = function () {
                // similar behavior as clicking on a link
                window.location.href = "/redirectTo404.aspx";
            }
        </script>

    Application is developed using VB.Net, .Net framework is 4.6.1

    Tuesday, February 9, 2021 9:20 PM

Answers

  • User-939850651 posted

    Hi TimJim,

    I cannot directly use response.redirect in the global.asax because I need to record detailed error info in the IIS log. If directly redirecting to custom error page, the search function works but I cannot have enough IIS log information (for example: I want IIS log to record the page name which is before hitting error page). 

    Before: Global.asax -> Server Transfer -> Custom Error Page (Search function on this page is broken.)

    After: Global.asax -> Server Transfer -> Intermediate HTML page -> Redirect -> Custom Error Page (Search function works by doing this)

    Do you think it is a good practice? Can you think any disadvantages or any harms to application for using this? I tried several methods but it seems to be the only solution for me. 

    As far as I know, I think there is no harm with this method.

    Because it only implements page jumps, and does not include functions such as Form, Submit operation, etc.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 10, 2021 8:13 AM

All replies

  • User-939850651 posted

    Hi TimJim,

    I cannot directly use response.redirect in the global.asax because I need to record detailed error info in the IIS log. If directly redirecting to custom error page, the search function works but I cannot have enough IIS log information (for example: I want IIS log to record the page name which is before hitting error page). 

    Before: Global.asax -> Server Transfer -> Custom Error Page (Search function on this page is broken.)

    After: Global.asax -> Server Transfer -> Intermediate HTML page -> Redirect -> Custom Error Page (Search function works by doing this)

    Do you think it is a good practice? Can you think any disadvantages or any harms to application for using this? I tried several methods but it seems to be the only solution for me. 

    As far as I know, I think there is no harm with this method.

    Because it only implements page jumps, and does not include functions such as Form, Submit operation, etc.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 10, 2021 8:13 AM
  • User1555919309 posted

    Thank you so much for you answer. 

    Thursday, February 11, 2021 9:01 PM