Solved

Try Catch  question

Posted on 2011-09-29
2
248 Views
Last Modified: 2012-06-21
I'm looking at this code:
    protected void Page_Load(object sender, EventArgs e)
    {
        //Session["LoggedOut"] = true;  removed trs 09/26/2011
        //Session["IsLoggedIn"] = false;  removed trs 09/26/2011
        log4net.ThreadContext.Properties["Action"] = "Logout";
        log.Info("User Logged Out");
        Response.Cookies[FormsAuthentication.FormsCookieName].Expires = DateTime.Now.AddYears(-1);
        FormsAuthentication.SignOut();
        Session.Abandon();
        //Session.Clear();// hold trs 09/26/2011'
        Response.Redirect("~/weblogin.aspx");
        //FormsAuthentication.RedirectToLoginPage();
    }
}
 Would I need a try/catch for the response.redirect to sink the theardAbortException when it calls the response.end?  What would that look like.
0
Comment
Question by:TimSweet220
2 Comments
 
LVL 9

Accepted Solution

by:
richard_hughes earned 500 total points
ID: 36890858
Hello TimSweet220

No, you would not need a Try/Catch block in order for this.Response.Redirect to work. Response.Redirect works in 2 different ways:

this.Response.Redirect("~/MyPage.aspx");

and

this.Response.Redirect("~/MyPage.aspx", true);

The above examples do not perform an actual redirect themselves. They return a HTTP code which tells the browser to redirect to the respective page, similar to if you typed it into the address yourself.

The difference with the 2nd example is it stops the response (and the thread eventually) there and then. The first example lets the response continue as normal.

With either example no Try/Catch block is needed.

Thanks,

Richard Hughes
0
 

Author Closing Comment

by:TimSweet220
ID: 36892241
Perfect
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now