Solved

Try Catch  question

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

911 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

20 Experts available now in Live!

Get 1:1 Help Now