Thursday, June 22, 2006

Response.Redirect

As a ASP coder I used a lot of Response.Redirect(webiste) statements while scripting and that was good...but now..when jumping to ASP.net and C# I had a few problems while using Response.Redirect("website")...and that is because I was placing the redirect statements into try-catch blocks and the Response.Redirect("website") statement throws an exception ThreadAbortException so if you try something like this:

try
{
///code that might throw exceptions
Response.Redirect("default.aspx");
}
catch(ThreadAbortException ex)
{
Response.Redirect("error.aspx")
}


you would always get the user to the error.aspx page instead of the default.aspx. The same thing happens if you try to use Response.Redirect("Default.aspx",true).

This happens because the Response.Redirect method calls the Response.End method that thrown this ThreadAbortException. There are several ways to avoid this problems:
1.
string url = String.Empty;
try
{
///code that might throw exceptions
url="default.aspx";
}
catch(ThreadAbortException ex)
{
url="error.aspx";
}
Response.Redirect(url);


This will redirect the user to the default.aspx page because the ThreadAbortException is not thrown by the Response.End method anymore.
2.
try
{
///code that might throw exceptions
Response.Redirect("default.aspx",false);
}
catch(ThreadAbortException ex)
{
Response.Redirect("error.aspx")
}

This will work fine(getting the user to the default.aspx page) because the false parameter in the Response.Redirect means that the Response.Redirect meghod will not call the Response.End method...but this could cause other damage so usually if you use this method put a return; statement after the redirect. Like this:
try{
///code that might throw exceptions
Response.Redirect("default.aspx",false);
return;
}
catch(ThreadAbortException ex)
{
Response.Redirect("error.aspx")
}



3. You can use Server.Transfer instead of Response.Redirect though this has its drawbacks too. First of all Server.Transfer transfers the user to another page on the server side so the user does not see the actual URL of the page that he is working on so getting the page in the favourites folder is not an option.

Microsoft and Robotics

I just found out that Microsoft has released a new tool that would help control robots. I looked over the Channel9 video and I was AMASED. This is too good to be true..I think that controling robots through a nice programming language like C#/VB.net will help improve the way robots "Think" today :)...I didn`t get a change to play with the simulation studio but...from what I`ve seen it looks nice...good work..

Wednesday, June 07, 2006

Google`s Office charge

Yesterday I read a news on Google news that Google will have a Web 2.0 application that be similar to Microsoft Excel(Google Spreadsheets)....so I signed up and had to wait for a confirmation a few hours because everyone(like me) wanted to know what that`s like....and the answer is....It`s COOL...it`s a really nice addition to google`s set of applications...you can`t really do everyting you can do in Excel right now but it`s only in the Lab now :).. what I liked is that you can easily share the spreadsheet with your business partners/friends....you can use some of Excel`s formulas.....but.... when it comes to getting data in...it`s not Excel...I had a table that I wanted to paste in and sort on some numbers(sorting works great,don`t get me wrong)....and simply couldn`t do that...though it has cut/copy/paste features this don`t work as expected...until improved....getting data in is quite hard..also some formulas don`t yet work as expected...and I had a little trouble aquaiting with sorting..but...overall...it`s a good project...and really really usefull....
A good integration with Google talk,calendar and other newly released applications might get things really really interesting....nice stuff :)...surf`s up