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
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
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
3 Points
11 Posts
Creating a Intermediate html page in the Global ASAX for redirection. Is it a good practice?
Feb 09, 2021 09:20 PM|TimJin|LINK
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
Contributor
2090 Points
670 Posts
Re: Creating a Intermediate html page in the Global ASAX for redirection. Is it a good practice?
Feb 10, 2021 08:13 AM|XuDong Peng|LINK
Hi TimJim,
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
Member
3 Points
11 Posts
Re: Creating a Intermediate html page in the Global ASAX for redirection. Is it a good practice?
Feb 11, 2021 09:01 PM|TimJin|LINK
Thank you so much for you answer.