Response.Redirect throws an exception?!!

by volkanuzun 8/11/2008 10:56:00 AM

One of my collegue asked my help today about his login page throwing an exception. He is using membership provider to authenicate the users however he is not using role provider. In the login page code behind file, he authenticates the user, and checks the user's role and Response.Redirect to a new  page depending on the role. (Dont ask me why not role provider?). A sample code is :

try{
        if(User.IsInRole("guest")
             Response.Redirect("/guest.aspx");
       else if(User.IsInRole("member")
             ....
      }
     catch{
     .....
}

Now that the above code is always throwing an exception, i googled it, and found out that Response.Redirect(url,bool end) , the second parameter means end the current thread if it is true. By default it is true, which means kill the thread and redirect to url, however, the code is in a try catch block, which wont simply kill the thread, and will throw an exception. The easiest solution will be changing true to false; however i am not suer about the performance when you let the current thread run to finish and navigate to the second page. So i recommended him removing try catch :)

Tags:

About the author

Volkan Uzun




E-mail me Send mail

Twitter

Calendar

<<  August 2008  >>
MoTuWeThFrSaSu
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar

Flickr Badge

www.flickr.com
This is a Flickr badge showing public photos from volkanuzun. Make your own badge here.

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009

Sign in