Response.Redirect cause Thread Aborted error

by Edward 25 August 2009 06:32

I came accross an old enemy of ASP.NET developers. In some cases you would click a button, do something and then redirect the user to another page, but then you might have an error along the lines of "Thread was being aborted" popup if you run the page in debug mode.

The main reason why this will happen is, is that you have your redirect in a try/catch block. This is not the way to do it.

There are a few ways around this error, however I am going to point out two easy ways to handle this error.

1) Use the Response.Redirect outside a try/catch block:

The Response.Redirect fails within a try/catch block, because the thread stops execution when it reaches this line and it could be avoided. It is better to do the Response.Redirect outside the try/catch block.


    try
    {
                 // Your actual code
    }
    catch (Exception ex)
    {
                // Catch the error, or Write actual error handling code here
        // Make sure the page returns or the error is handled from here or the next line will be read.
    }

    //Response.Redirect to next page
    Response.Redirect("About_Dascode.aspx");


2) Handle the exception:

You need to handle the "ThreadAbort" exception separately and do nothing if it is thrown. Also catch the ThreadAbortException before any other exceptions, otherwise the code will not catch the error and

    try
    {
                // Your code here

        // Redirect to another page
                Response.Redirect("About_Dascode.aspx");
    }
    catch (ThreadAbortException exc)
    {
                 // This should be first catch block i.e. before generic Exception
                 // This Catch block is to absorb exception thrown by Response.Redirect
    }
    catch (Exception ex)
    {
                // Write actual error handling code here
    }


Either way will be the correct way, however if you are not keen on handling the "ThreadAbort" exception, use the first option.

Tags: , , , ,

ASP.NET

Windows 7 Code Pack V1.0 Released

by Edward 22 August 2009 08:43

Following the release of the gold build of Windows 7 via MSDN and TechNet, Microsoft has now made available for download Windows 7 Code Pack 1.0.

The Windows API Code Pack for Microsoft .NET Framework provides a source code library that can be used to access some of the new Windows 7 features (and some features of older versions of the Windows Operating System) from managed code. These Windows features are not available to developers today in the .NET Framework.

This Code Pack also includes reference for the API. API documentation files can be found in two separate files "WindowsAPICodePackHelp" and "DirectXCodePackHelp" in the download section.

Here are some of the features  by using the Code Pack:

  • Windows 7 Taskbar Jump Lists, Icon Overlay, Progress Bar, Tabbed Thumbnails, and Thumbnail Toolbars.
  • Windows 7 Libraries, Known Folders, non-file system containers.
  • Windows Shell Search API support, a hierarchy of Shell Namespace entities, and Drag and Drop functionality for Shell Objects.
  • Explorer Browser Control.
  • Shell property system.
  • Windows Vista and Windows 7 Common File Dialogs, including custom controls.
  • Windows Vista and Windows 7 Task Dialogs.
  • Direct3D 11.0, Direct3D 10.1/10.0, DXGI 1.0/1.1, Direct2D 1.0, DirectWrite, Windows Imaging Component (WIC) APIs. (DirectWrite and WIC have partial support)
  • Sensor Platform APIs
  • Extended Linguistic Services APIs
  • Power Management APIs
  • Application Restart and Recovery APIs
  • Network List Manager APIs
  • Command Link control and System defined Shell icons.


Developers will also need .NET Framework 3.5 SP1 and Windows 7 RTM installed,  in order to take advantage of the new Code Pack.

Tags: , , , ,

ASP.NET | Development Resources

Microsoft roll out free trial of SQL Azure Database

by Edward 21 August 2009 11:55

Microsoft has rolled out a free trial of its cloud-based relational database, SQL Azure Database.

SQL Azure Database, a key component of the platform, is to rival Amazon's SimpleDB. SimpleDB is a distributed database written in "Erlang" by Amazon.com. It is used as a web service in concert with Amazon Elastic Compute Cloud (EC2) and Amazon S3 and is part of Amazon Web Services. Unlike the Amazon service however, it is a relational database. As with all cloud platforms, the idea is to provide scalable, hosted services on a pay-per-use basis, running remotely in Microsoft's datacentres.

Also available as a CTP. is the SQL Server Driver for PHP 1.1, which provides new capabilities for building PHP applications and support for SQL Azure, enabling developers to build PHP applications, with relational database capabilities using SQL Server or SQL Azure Database. 

With SQL Azure organizations will benefit from a pay-as-you grow model with enterprise-class availability, data protection, scalability, and security.

The free trial of SQL Azure Database will last until November, when the service is fully rolled out.

There will be two editions of the SQL Azure Database:

  • Web Edition storing up to 1GB of data and costing $9.99 (£6) per month, and
  • Business Edition that stores up to 10GB at $99.99 per month.

 

Tags: ,

ASP.NET | Development Resources | Technology

How to validate a Integer or Double in C#

by Edward 20 August 2009 18:09

I have come across a web site that does not really use validation to check for user input. One of the key validation errors I have seen is the check if a value is int or double. If you don't know, int values are "whole numbers", and cannot a decimal type value, for example "5.5". If you need to store "non-whole numbers", you need to store it either as a double, float or decimal. Decimal should only be used when storing values that needs to be rounded at the second value after the decimal. Rather use double or float. They are lighter, and store values up to one value after the decimal point (e.g. "5.5").

From the MSDN library:


The int keyword denotes an integral type that stores values according to the size and range from -2,147,483,648 to 2,147,483,647.

The double keyword denotes a simple type that stores 64-bit floating-point values. The approximate range for the double type is ±5.0 × 10−324 to ±1.7 × 10308.

As you can see there is a huge difference in terms of the range each value type can handle.

Here is a simple example of how to check if a value entered into a textbox is of type int, or type double.

int intOutput = 0;
    if (Int32.TryParse(txtNumericTest.Text, out intOutput))
    {
        Response.Write("Valid int");
    }
    else
    {
        Response.Write("Not a Valid int");
    }

//To check Double values

    double dOutput = 0;
    if (Double.TryParse(txtNumericTest.Text, out dOutput))
    {
        Response.Write("Valid double");
    }
    else
    {
        Response.Write("Not a Valid double");
    }

 

Tags: , ,

ASP.NET

Microsoft not to give up on Internet Explorer 6

by Edward 12 August 2009 09:05

Microsoft responded to suggestions that they are considering to stop supporting Internet Explorer 6 to upgrade to the newer versions of their popular browser. Several technology sites have reported that Microsoft plans to cease support for the browser, while still commanding the market share(27.2% for July), and leading Firefox which is down in 3rd place.

Sites like YouTube and Digg are considering dropping support for the browser as they are growing increasingly frustrated with re-coding their site to support Internet Explorer 6.

However Microsoft says that it will not force consumers to upgrade. They state that the choice belongs to the user, and the user has to right to upgrade their hardware and software at their discretion.

Tags: , , ,

Other | Technology

Microsoft releases Windows 7 to IT Pros

by Edward 06 August 2009 17:52

Microsoft made Windows 7 available to certain IT professional, manufacturers and software developers today. Unfortunately I am not one of them.

Tech pros who subscribe to Microsoft's TechNet program can download the operating system from today, as well as independent hardware and software vendors. Individuals or companies with Software Assurance subscriptions can download Windows 7 from this Friday.

Windows 7 is due to hit the shelves on 22 October 2009, and this "pre release" is to make sure that when it becomes available to the man on the street, it will be bug-free, and also fully supported and be available on new computer models.

Microsoft is hoping that Windows 7 will kick-start their software sales. Vista, which was released less than 4 years ago, and Windows 7's predecessor, proved unpopular with many consumers and was largely shunned by the corporate market for its intrusive security measures and incompatibility with older applications.

Tags: , ,

Development Resources | Other | Technology

About DasCode.Net

I'm a ASP.NET web developer and code enthusiast. Blogging about everything .Net related.

Code... that's .net

Month List