Tuesday, May 24, 2011

Return different HTTP response codes from Response.Redirect call in ASP.NET

As explained in my previous post, HttpResponse.Redirect performs the redirection by returning a 302 HTTP status code. A 302 response is generally indicative of “Moved Temporarily”. There is no default mechanism provided a return a different redirection code.

So how can we implement this. Short answer: using C# extension methods. Let’s look at some code below to understand this more clearly:

This code is elegant and simple (written by one very talented dev in my team). As you can see, we are building the response object in the function and are setting the correct status code and description for each specific case. We will discuss extension methods in detail in a later post.

Thank you! Thank you! Thank you! Your blog was a total game changer!When other tuning techniques fail to achieve the desired throughput or response time for the application, we need to consider analysing the code base and try optimizing it. I'm learning to process sound in Java, and I thought I would start with the "javax.sound.sampled" package. I thought I would open a wav file and then play it through my computer's speaker.I'm calling javax.sound.sampled.AudioSystem. getAudioInputStream(InputStream), and getting an exception, and now I'm feeling kind of lost. The exception is:java.io.IOException: mark/reset not supportedI guess it means I need some kind of better AudioInputStream class (one which supports mark/reset), or maybe it doesn't like the wav file which I picked? (I just picked some random wav file out of a /Windows/Media directory, like "alarm01.wav".)I read multiple articles and watched many videos about how to use this tool - and was still confused! Your instructions were easy to understand and made the process simple.