Solved

Try Catch  question

Posted on 2011-09-29
2
250 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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