Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Suppress exception
Message
From
08/01/2014 10:10:20
 
 
To
08/01/2014 08:37:57
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01591488
Message ID:
01591498
Views:
31
Hi
Actually, I am using 3rd party tool which I guess having TRY...CATCH in place, and scoped in calling corresponding base method and event.
I have code that respond to the event, which will call response.End() as below

Even though I have suppressed the ThreadAbortedException, but somehow the caller program still able to catch it, and show an error message. I tried to change response.End to /HttpContext.Current.ApplicationInstance.CompleteRequest(), but it have another issue that the execution will be continue, which shouldn't once "Redirect" called. Therefore, I am thinking any possible to "hide" the exception from caller program.
            try
            {
                HttpResponse response = HttpContext.Current.Response;
                Page p = HttpContext.Current.Handler as Page;

                if (p == null) throw new Exception("Page is not an object");

                string resolvedUrl = p.ResolveUrl(url);

                response.Buffer = true;
                response.Status = "302 Object moved";
                response.AddHeader("Location", resolvedUrl);
                response.Write("<HTML><Head>");
                response.Write("<META HTTP-EQUIV=Refresh CONTENT=\"2;URL=" + resolvedUrl + "\">");
                response.Write("<Script>window.location='" + resolvedUrl + "';</Script>");
                response.Write("</Head>");
                response.Write("</HTML>");

                try
                {
                    response.End();

                    //-- Remarked as the code after this method will be still executed.
                    //-- We always want to stop any execution after "redirect"
                    //HttpContext.Current.ApplicationInstance.CompleteRequest();
                }
                catch
                { 
                    //-- To Prevent warning msg logged in event viewer
                }
            }
            catch (ThreadAbortException exc)
            {
                // This should be first catch block i.e. before generic Exception
                // This Catch block is to absorb exception thrown by Response.End
            }
            catch (Exception exc)
            {
                // Write actual error handling code here
            }
I am not the most powerful man in this world.
I am not the worst man in this world either.
I just as same as all of you.
I still need to learn from my mistakes...
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform