Solved

Try Catch  question

Posted on 2011-09-29
2
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

705 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