X

Response.Redirect and Response.End

I discovered once myself automatically writing some redirects on ASP.NET pages and I started thinking about API behind these redirects and code readability. Here is what I came out with.

Directs were like this:

Response.Redirect("otherpage.aspx"); 
Response.End();

Well, what’s the point writing code the way shown above if I can write same thing two ways as follows:

Response.Redirect("otherpage.aspx");
Response.Redirect("otherpage.aspx", true);

My point is simple. ASP.NET allows processing continue also after headers are sent to browser. This way we can send user to another page and do some more actions on page. Okay, I want to write about my habit, not about Response.Redirect functional side You can find more about Response.Redirect from C6 Software article Response.Redirect(url) ThreadAbortException Solution.

What is the point of using two lines given in first code example instead of one of those that are shown in second example?

At first, if some other coder reads my code then he or she can see without further thinking and guessing that this is the point where response ends. So there is not much chances that somebody writes code after Response.End and wonders later why this code is never executed.

The second reason why I prefer first style is that the second one has boolean argument. It can have only values true and false and it is not easy to read about what depends on these true and false values. If there was enumerator it was much better because we can use enumerators to give understandable values to different constants we can use in same place.

Of course, now we can use enumerator because we have extension methods. Using extension methods it is possible to write new Response.Redirect method. Something like this:

public enum ResponseEndEnum
{
    EndResponse,
    ContinueResponse
}

public static class HttpResponseExtensions
{
    public static void Redirect(this HttpResponse response, string url,
ResponseEndEnum
responseEnd)
    {
        bool end = (responseEnd == ResponseEndEnum.EndResponse);
        response.Redirect(url, end);
    }
}

Now if we need to redirect user to another page we can write redirect this way:

Response.Redirect("otherpage.aspx", ResponseEndEnum.EndResponse);

As you can see it all about readibility of the code. Or using another words – saving the time of other people who work with me or who will update my code later.

Liked this post? Empower your friends by sharing it!
Categories: ASP.NET

View Comments (361)

  • This will never work....

    Response.Redirect("otherpage.aspx");

    Response.End();

    Response.End(); is never going to get called because you have already redirected the response to another page. Create this statement, set a breakpoint on the Response.End(); and watch it never get called.

    The second approach you mentioned using the ResponseEndEnum will work fine, but your argument is moot as your first approach doesn't work.

  • First approach works because redirection takes place. Just Response.End is not run. It is there like "Game Over" when you get killed in action game. It is not part of game, there is no action anymore and it is purely informative. It sais to reader that there happens nothing after redirect - it is the point where response is over.

  • Wow, this post is pleasant, my younger sister is analyzing these things,
    so I am going to tell her.

  • Pretty nice post. I just stumbled upon your weblog and wanted to say that
    I have truly enjoyed browsing your blog posts. After all
    I will be subscribing to your feed and I
    hope you write again soon!

  • Do you mind if I quote a couple of your articles as long as I provide credit and
    sources back to your weblog? My blog site is in the very same area of interest as yours and my visitors would truly benefit from
    some of the information you provide here. Please let
    me know if this okay with you. Regards!

  • Phim Yen Vi is known for her appearances in adult films in Vietnam.

    The actress has appeared in multiple films there that
    have been extremely popular and also in other
    countries.

  • I loved as much as you'll receive carried out right here.
    The sketch is attractive, your authored subject matter stylish.
    nonetheless, you command get bought an impatience over
    that you wish be delivering the following. unwell unquestionably come further formerly again as exactly the same nearly a lot often inside
    case you shield this increase.

  • Hey! I'm at work browsing your blog from my new iphone 4!
    Just wanted to say I love reading your blog and look
    forward to all your posts! Carry on the fantastic work!

  • Wonderful post! We are linking to this great content on our
    website. Keep up the good writing.

  • London website gency offering expertt WordPress websaite design services.
    Ԍet a free SEO strategy ɑnd custom WordPress designs tto increase online visitors аnd
    sales.

  • Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your blog?

    My blog site is in the very same niche as yours and my users would certainly
    benefit from a lot of the information you provide here. Please let me know if this alright with you.

    Thanks a lot!

  • Hawkplay vip - Υou can Usе GCash tօ play in anytime
    Free Spins 1000+ Free Demo Slot
    Openning Bonus 120% piso Ьack
    Searching hawkplay casino ߋn Google ᧐r Bing to ցеt free coins

    hawkplay vip login

  • You really make it appear so easy along with your presentation but I
    to find this topic to be really something that I think I would by no means understand.
    It seems too complicated and extremely extensive for me.
    I am having a look ahead in your subsequent submit, I'll attempt to get the cling of it!

  • id="firstHeading" class="firstHeading mw-first-heading">Search results

    Help

    English

    Tools

    Tools
    move to sidebar hide

    Actions

    General

  • Hello to all, how is the whole thing, I think every one is getting more from this web site,
    and your views are fastidious for new people.

  • Hello just wanted to give you a quick heads up. The text in your article seem to be running off the screen in Chrome.

    I'm not sure if this is a formatting issue
    or something to do with internet browser compatibility but I thought I'd post to let
    you know. The style and design look great though!
    Hope you get the problem fixed soon. Many
    thanks

  • This was really a dream c' was one of these nights when Jasmine was very tired, but the sleep it eluded because it was anxious for her boyfriend, Pat, why.
    Stalemate was to remain at the house of his ex-small friend, then one sleeps was not really with to arrive.
    They had left all to Dubai because Pat affirmed quad' it n' did not
    have considering the parents of sound sex within such a long time, and after all,
    they were "like of the family.

    Right of the Jasmine compensated for thought "congeries". Five d' between them had met and lunched, we touched the casino for a few hours. Ex Pat, Emma, gave him the eyes all the evening, which Jasmine anger, but she refused FUCK BUTTONS to increase and contained its anger. Soon after having to dine, it was d' approximately nine hours and Pat the large one had idea qu' they must turn over to the house d' summer of the family and to catch up with them. Jasmine do not please support it and learn how to know these people, but it was blatantly obvious quad' they l' did not like. Jasmine from Manchester and from grew does not think of having the good things as the fast cars and clothing of creators and others.

    Then, it n' was not going to put itself in torture then quid' they spoke about their hearths a million dollars in Los Angeles and l' education of their daughter of TIGHT WHITE. They had already made feel with place where it showed Justus' to wear jeans skinny, apartments, and semi Signal held relaxed, the mother d' Is Emma asked "that all you cherished?

    " It was at this time, Jasmine s' account is returned that if it stuck around for the remainder of the night, quell' one would finish is with l' hospital or under house arrest... and it would have most probably been sound. It was late and Jasmine wanted to really return to the room d' hotel. of kind she said Pat, she did not feel well and qu' it should continue and have fun with everyone.

    He asked to me whether she were sure and quay' she would be to be OK alone and s' he must remain with it. Jasmine smiles and says: "Look at, c' is ok.
    You to go from l' before and to remember and
    I will retrogress and to rest a little. "Stalemate embraced and quad' says to him; it would be of return to take care d' it, promising not to be late.

    To enter the taxi to return to l' Jasmine hotel could not s' to prevent from thinking: "I am
    sure that if c' was in Emma, you will be by taking care d' it too.
    " Once it returned to l' hotel and drawn in a space from parking, it obtained one message text to leave d' a certain unknown number.

    Jasmine was furious and all this GAY SEX it could think was "Oh COCKPIT,
    it is definitively to make this qu' she wants with him maintaining!

    " dandies the stimulation of the room at the same time. It s' sat on the bed and tried to think positive on him pace quid' it l' liked and n' was not going to leave anything to arrive. It lay down and closed the eyes, and took great breathings and with last was deeply deadened.

  • Every weekend i used to go to see this website,
    because i want enjoyment, as this this site conations in fact good
    funny stuff too.

  • Crash Bandicoot gets his nickname "Crash" from his tendency to crash through obstacles and
    enemies in his adventures. His reckless and adventurous nat
    Read more

    Vermont

    +1

    Why do people visit Vermont?

    Asked by Anonymous

    People visit Vermont for its natural beauty, including picturesque fall foliage, charming small towns, and outdoor recreational
    opportunities such as skiing and
    Read more

    Vermont

    +2

    Which state is further north Indiana or Vermont?

    Asked by Anonymous

    Vermont is further north than Indiana. Indiana is farther south than Vermont.

  • Hi there, I read your blog daily. Your story-telling style is awesome, keep it up!

  • Hi there, I read your blog daily. Your story-telling style is awesome, keep it up!

  • What's Going down i'm new to this, I stumbled upon this I've discovered
    It absolutely useful and it has helped me out loads. I hope
    to give a contribution & help different customers like its aided me.
    Great job.

  • I love your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to
    do it for you? Plz answer back as I'm looking to construct
    my own blog and would like to know where u got this from.

    thanks

  • To reuse an MTN airtime voucher, you typically cannot use the same voucher again, as it is designed
    for one-time use. Once the voucher code is redeemed, it cann
    Read more

    Facebook

    +2

    How do you delete a hot topic account?

    Asked by Anonymous

    To delete a Hot Topic account, log in to your account on their website.
    Navigate to the account settings or profile section, where
    you may find an option for ac
    Read more

    Performing Arts

    +4

    How do you pole dance on Habbo?

    Asked by Anonymous

    Well, honey, to pole dance on Habbo, you gotta find a pole in one of the public rooms or buy one from the catalog.
    Once you got your pole, just click on it
    and
    Read more

    iPod

    +1

    How do you ake a Habbo music CD?

    Asked by Anonymous

    Habbo

    Who is btdi jv llp?

    Asked by Anonymous

    Astronomy

    +2

    What is hc in astronomy?

    Asked by Anonymous

    In astronomy, "hc" typically refers to the product of Planck's constant (h) and the speed of
    light (c). This product, denoted as hc, has units of ener
    Read more

    Swimming Pools

    +3

    What is an aqua door?

    Asked by Anonymous

    An aqua door is a door that is colored in shades of blue-green resembling
    the color of water. This can add a unique and eye-catching element to
    a room or buildi
    Read more

    Video Games

    +1

    How do you delete Habbo rooms?

    Asked by Anonymous

    Hii :). Yes you can delete rooms on Habbo. Here's how to do it.
    - Go to the room you want to delete, then click "Room Info" then go to "Room Settings".
    After yo
    Read more

    Social Network Websites

    +2

    Where to download Habbo hacks?

    Asked by Anonymous

    Well you can download Habbo Zeldah where u can get as much furni as you want any
    furniture and heaps of creds i dont have it but.

  • Hurrah, that's what I was searching for, what a
    information! existing here at this weblog, thanks admin of this
    web page.

  • I do agree with all the concepts you have offered for your
    post. They are really convincing and will definitely
    work. Nonetheless, the posts are very brief for beginners.
    May just you please lengthen them a little from
    next time? Thanks for the post.

  • It's enormous that you are getting thoughts from this article
    as well as from our dialogue made at this time.

  • Fantastic site you have here but I was curious if you knew of any community forums that cover the same topics talked
    about here? I'd really love to be a part of community where I can get feed-back from other knowledgeable people that share the same interest.

    If you have any suggestions, please let me know. Cheers!

  • Hi there every one, here every person is sharing such
    know-how, therefore it's fastidious to read
    this webpage, and I used to visit this web site daily.

  • My brother recommended I might like this blog. He was once totally right.
    This put up truly made my day. You can not believe simply how much time I had spent for this information! Thank you!

  • Hmm is anyone else having problems with the images on this blog loading?
    I'm trying to find out if its a problem on my end or if it's the blog.
    Any suggestions would be greatly appreciated.

  • I think that is among the so much important info for me.
    And i am happy studying your article. But should remark on few general
    issues, The site style is ideal, the articles is really excellent : D.
    Good process, cheers

  • Pretty! This was an exttremely wonderful article. Many thanks for
    supplying this information.

  • Hi there friends, how is everything, and what you want to say concerning this piece of writing, in my view its truly remarkable for
    me.

  • Very nice post. I just stumbled upon your blog and wanted to say that I have truly enjoyed surfing around your weblog posts.
    After all I'll be subscribing to your rss feed and I'm hoping you write again very soon!

  • Hi there! Quick question that's totally off topic.
    Do you know how to make your site mobile friendly?My
    site looks weird when viewing from my iphone 4. I'm
    trying to find a theme or plugin that might be able to fix this problem.
    If you have any recommendations, please share. Cheers!

    Have a look at my web blog :: source

  • Magnificent goods from you, man. I've understand your stuff previous to and you are just too magnificent.
    I really like what you've acquired here, certainly like what you're saying and the way in which you
    say it. You make it entertaining and you still take care of to keep it wise.
    I cant wait to read far more from you. This is really a great
    website.

  • I am really impressed witһ yօur writing skills аnd also wіtһ the layout oon your weblog.
    Is thiѕ a paid theme or did you customize it
    yourself? Either waay keeⲣ up tһe nice quality writing, it iѕ rare t᧐ see ɑ nice blog like this ߋne thеse days.

    my web blog :: Buy Neurocaine Powder Online Usa

  • I loved as much as you'll receive carried out right here.
    The sketch is tasteful, your authored material stylish.

    nonetheless, you command get bought an edginess over that you wish
    be delivering the following. unwell unquestionably come more formerly again since exactly the same nearly
    very often inside case you shield this increase.

  • Hello there! Quick question that's completely off topic.
    Do you know how to make your site mobile friendly? My
    site looks weird when browsing from my iphone 4.

    I'm trying to find a theme or plugin that might be able to resolve this problem.
    If you have any suggestions, please share.
    Thanks!

  • Everything is very open with a really clear description of the challenges.
    It was truly informative. Your website is extremely helpful.
    Thank you for sharing!

  • Having read this I thought it was rather informative.
    I appreciate you finding the time and energy to put this short article together.
    I once again find myself spending way too much time both reading and posting comments.
    But so what, it was still worthwhile!

  • I'm truly enjoying the design and layout of your website.
    It's a very easy on the eyes which makes it much more enjoyable for me
    to come here and visit more often. Did you hire out a designer to create your theme?
    Superb work!

  • Excellent beat ! I wish to apprentice whilst you amend your web site, how could i subscribe for a weblog web site?
    The account aided me a appropriate deal. I had been tiny bit
    acquainted of this your broadcast provided bright transparent
    idea

  • What's up, I log on to your blog daily. Your writing style is awesome, keep doing what you're doing!

  • Nice post. I used to be checking continuously this weblog and I
    am inspired! Extremely useful information specifically the remaining phase :
    ) I take care of such information much. I was seeking this particular info for a
    very long time. Thank you and good luck.

  • We are a group of volunteers and starting a new scheme in our community.
    Your web site provided us with valuable information to work on.
    You have done a formidable process and our entire community shall be thankful
    to you.

  • Howdy! I just wish to offer you a big thumbs up for
    your great info you have got here on this post.
    I'll be returning to your site for more soon.

  • Thank you for sharing your thoughts. I truly
    appreciate your efforts and I will be waiting for
    your next post thanks once again.

  • Just looked at a few of the rates (: I'm truly delighted I found this service.
    It's wonderful!

  • id="firstHeading" class="firstHeading mw-first-heading">Search results

    Help

    English

    Tools

    Tools
    move to sidebar hide

    Actions

    General

  • Fastidious response in return of this matter with firm arguments and telling the whole thing concerning that.

  • id="firstHeading" class="firstHeading mw-first-heading">Search results

    Help

    English

    Tools

    Tools
    move to sidebar hide

    Actions

    General

  • Discover residential park homes forr sale ɑt Sussex Park Homes.
    Explore brand neԝ, affordable homes іn a secure riverside community.
    Contact սѕ todaʏ!

  • Very shortly this web site will be famous amid all blogging users,
    due to it's fastidious articles or reviews

  • Hi there just wanted to give you a quick heads up.

    The words in your article seem to be running off the screen in Ie.
    I'm not sure if this is a formatting issue or something to do with web browser compatibility but I figured I'd post to let you know.
    The design and style look great though! Hope you get the problem resolved soon. Cheers

  • Hmm it appears like your blog ate my first comment (it was extremely long) so I guess I'll just sum it up what I wrote and say, I'm
    thoroughly enjoying your blog. I too am an aspiring blog blogger but I'm still new
    to the whole thing. Do you have any points for first-time blog writers?
    I'd definitely appreciate it.

  • What i don't understood is in truth how you are no longer
    actually a lot more neatly-appreciated than you might be right now.

    You're so intelligent. You already know therefore considerably in the case of this topic, produced me personally believe it from
    a lot of numerous angles. Its like women and men aren't involved except it is something to accomplish with Woman gaga!
    Your own stuffs nice. At all times handle it up!

  • Hiya! Quick question that's completely off topic. Do you know how to make your site
    mobile friendly? My weblog looks weird when browsing from my iphone4.
    I'm trying to find a template or plugin that might be able to correct
    this problem. If you have any recommendations, please share.
    Appreciate it!

  • Hi to every one, the contents existing at this website are
    genuinely remarkable for people experience, well, keep up
    the nice work fellows.

  • Quality posts is the secret to invite the viewers to pay a visit the site, that's what this web page is providing.

  • you are in point of fact a just right webmaster. The web site
    loading speed is incredible. It kind of feels that you're doing any
    distinctive trick. In addition, The contents are masterpiece.
    you have performed a wonderful job on this topic!

  • Hello there! This article could not be written any better!
    Going through this article reminds me of my previous roommate!
    He continually kept preaching about this. I am going to send this
    information to him. Pretty sure he's going to have a very good read.
    I appreciate you for sharing!

  • This paragraph provides clear idea in support of the new viewers of blogging,
    that genuinely how to do blogging and site-building.

  • Hi! Someone in my Facebook group shared this website with us so I came
    to give it a look. I'm definitely loving the information. I'm book-marking
    and will be tweeting this to my followers!
    Exceptional blog and fantastic design.

  • I know this web site gives quality based articles and extra material, is
    there any other website which gives these stuff in quality?

  • I'm not sure why but this website is loading incredibly slow for me.
    Is anyone else having this issue or is it a issue on my end?
    I'll check back later on and see if the problem still exists.

  • A motivating discussion is worth comment. I think that you need to publish more on this subject matter, it may
    not be a taboo subject but generally people don't talk
    about these subjects. To the next! Best wishes!!

  • I like the valuable information you supply in your articles.
    I'll bookmark your weblog and test again here regularly.

    I'm somewhat sure I will be informed a lot
    of new stuff proper here! Best of luck for the following!

  • Greetings from Los angeles! I'm bored to tears at work so I decided to browse your
    website on my iphone during lunch break. I love the information you present here and can't wait to
    take a look when I get home. I'm surprised at how quick your
    blog loaded on my cell phone .. I'm not even using WIFI, just 3G ..

    Anyhow, good blog!

  • I am truly delighted to glance at this website posts which carries tons of useful information, thanks for providing such statistics.

  • Woah! I'm really digging the template/theme of this website.
    It's simple, yet effective. A lot of times it's difficult to get that "perfect balance" between usability and
    visual appearance. I must say you've done a fantastic
    job with this. In addition, the blog loads very fast for me on Safari.
    Outstanding Blog!

  • No matter if some one searches for his required thing,
    therefore he/she desires to be available that in detail, thus that thing is maintained over here.

  • Right now it looks like Drupal is the preferred blogging platform available right now.
    (from what I've read) Is that what you're using on your blog?

  • Thank you for the auspicious writeup. It in fact was a amusement account it.
    Look advanced to more added agreeable from you!
    By the way, how can we communicate?

  • Hello, I think your blog might be having browser compatibility issues.
    When I look at your blog in Ie, it looks fine but when opening in Internet Explorer,
    it has some overlapping. I just wanted to give you a
    quick heads up! Other then that, wonderful blog!

  • Hi, I think your blog might be having browser compatibility issues.

    When I look at your blog site in Chrome, it looks fine but when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up!
    Other then that, amazing blog!

  • This is a topic which is close to my heart...

    Thank you! Where are your contact details though?

  • id="firstHeading" class="firstHeading mw-first-heading">Search
    results

    Help

    English

    Tools

    Tools
    move to sidebar hide

    Actions

    General

  • When some one searches for his vital thing, therefore
    he/she wishes to be available that in detail, therefore that thing is maintained over here.

Related Post