When an error in global.asax fails to execute server.transfer

On my global.asax page, I have the following code:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) server.transfer("err.aspx") End Sub 

This does not work, and I get the following error: The object reference is not installed in the object instance.

Thanks in advance

+4
source share
1 answer

I would recommend using the built-in error handling in .NET for this, just use Web.config:

 <configuration> <system.web> <customErrors mode="On" defaultRedirect="err.aspx" redirectMode="responseRewrite"> </customErrors> </system.web> </configuration> 

responseRewrite will make it valid as Server.Transfer. If you want to redirect, use redirectMode="responseRedirect" .

More details here:

However, if you really want to process it in Global.asax, you must use the sender object:

 Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) Dim app As HttpApplication = CType(sender, HttpApplication) app.Server.Transfer("err.aspx") End Sub 
+8
source

Source: https://habr.com/ru/post/1499471/


All Articles