Thread aborted using Response.Redirect in ASP.Net

by demtron on Monday, February 02, 2009 08:13 AM

I added a Response.Redirect to a .Net Web page and began receiving a "Thread was being aborted" error on a line of code that executed Response.Redirect.  Without really considering it, this error made sense based on the place where I added the code.

Response.Redirect will call Response.End by design.  However, this will also raise a ThreadAbortException.  In my case, it was because the redirect line was within a try...catch block.  I found two ways to handle this:

  1. Change Response.Redirect(<URL>) to Response.Redirect(<URL>, false)
  2. Move the line to outside the try...catch block
I ended up using method #2, but both options worked for me.

Detect AJAX postback in Global.asax

by demtron on Friday, January 16, 2009 08:19 AM

I was recently working on a page hit logging scenario that, for reasons having to do with URL rewriting, needed to have the logging code executed in the Application.BeginRequest event of Global.ajax.  The application relies heavily on ASP.Net Ajax, and I needed a was to ferret out the AJAX requests and not log them.  Ordinarily, in the page lifecycle, this would be accomplished by using Page.IsAsync.  In this case, I needed to perform the logging prior to the page code being invoked.

To determine the whether the request was generated by AJAX, I used the following code:

VB.Net

Request.Headers("X-MicrosoftAjax") = "Delta=true"

C#

Request.Headers["X-MicrosoftAjax"] = "Delta=true";

Hope that helps someone out there who has struggled to find an easy answer.


Identifying a Nullable Type Programmatically in Visual Studio

by demtron on Tuesday, December 16, 2008 05:34 PM

I have occasionally found a need to identify whether the type of a given variable is a nullable type so that I know whether I need to also use the HasValue and Value methods to obtain its contained value.  Here's a farily simple snippet of code to accomplish this.

VB.NET:
If type.IsGenericType AndAlso type.GetGenericTypeDefinition() = GetType(Nullable(Of )) Then
End If
C#:
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) {}

Powered by BlogEngine.NET 1.5.1.18
Theme by Mads Kristensen · Adapted by Demtron

Bookmark and Share

Calendar

<<  March 2017  >>
MoTuWeThFrSaSu
272812345
6789101112
13141516171819
20212223242526
272829303112
3456789

View posts in large calendar
Log in

Milwaukee SEO Company

Milwaukee Access Programmer/Developer

Milwaukee Website Designer and Developer



Marketing / SEO

Blog Directory
blogarama - the blog directory
TopOfBlogs
Milwaukee area SEO, SEM, ASP.Net