XYZCONSULTING

3/27/2009

Response.Redirect inside of a Try/Catch

Ok, first off, let me state, that I am not entirely certain WHY I did this in the first place.  I am going to say I was rushed and wasn’t thinking clearly.  However, I glazed over it and moved on and when it came time to test, I was getting bizarre behavior that didn’t throw an error.

Session[“var”] = “”; 

try 
{ 
    Session[“var”] = “Good Value”;

    Response.Redirect(“newpage.html”); 
} 
catch(Exception ex) 
{ 
    Session[“var”] = “Bad Value”; 
}

In the code above, Session[“var”] will ALWAYS equal “Bad Value”.  Why you may ask?

Response.Redirect throws a ThreadAbortException.  … Fun, no?

If you are building a URL inside of a try block that you want to then redirect to, declare a string, build your url, and then pass that on to the Response.Redirect statement. 

For Example:

string _url;

try 
{ 
    _url = “yourpage.aspx?var=” + iffyMethodCall(); 
} 
catch(InvalidOperationException ex) 
{ 
    _url = “error.html”; 
}

Response.Redirect(url);

So, If you ever run into odd behavior in a site you are working on and when debugging, your code goes straight past your Response.Redirect and into the catch block and the debugger starts giving you cryptic messages, this may be what you’re seeing.

12/7/2008

IIS Worker Process Fail 503 Error

Helping a friend to configure his new Win2k8 Server with IIS7 this weekend we ran into an issue where IIS kept returning 503 errors.

Examining the Application Event log I saw that  IISW3SVC-WP was quitting due to application errors. "The error is the data".  How helpful.

After a considerable amount of digging I discovered that in the Microsoft.Net/Framework/ folder, there was a beta version of v2 of the framework.  The only version that *should* be there is v2.0.50727. 

I deleted the beta version of the framework and restarted the IIS worker processes that were causing problems and everything immediately burst to life!

I've no clue what installed the beta version of the framework, but it is a definite lesson to make sure that when distributing a framework to be 100% certain that you are always including the latest "release" version... oh yeah, and perhaps doing a check for an existing version of said framework before installing.

At any rate, hope this helps somebody.

7/5/2007

Master Page Properties

Just a quick note for those of you who like to use Master pages in ASP.Net.

Have you ever had something on the Master page that you wished you could change from the child page? Well, for those of you who have actually done this, one way is to get the Master page from the Page object on the backend, search it for a control that you are after, cast that control to the right type, and ... you get the point. Long and tedius.

Try this instead: Create a property on the master page that reflects the thing you want to be able to change. On the child page, at the top add this directive:

 

<%@ MasterType VirtualPath="~/Default.master" %>

where Default.Master is the full path to the master page that the page is using. Then in the child's code behind, you can do something like:

 

Master.PropertyName = PropertyValue;

Should save a lot of time. Hope this is useful to someone.

5/1/2007

Silverlight, CoreCLR, DLR, oh My!

Wow... so lots has been going on lately. Adobe is trying to encroach on Microsoft's turf with Apollo and in reply, here comes Silverlight. Now, Silverlight by itself is alright. I am not going to profess that it is going to kick Flash to the curb by any means. To be honest, it has a ways to go before it will be a major competitor against the offering that Adobe already has out there. However, given that Flex is still being adopted for RIA development if Microsoft focuses their efforts with Silverlight to that front, then they will most likely succeed. They will succeed due to the sheer mass of people developing against their technologies. The big announcment that a lot of people seem to be overlooking in the big Flash vs. Silverlight debate is that beneath Silverlight lies something so massive that it could change things all by itself. CoreCLR. CoreCLR is a trimmed down CLR with all the goodies of the larger .Net Framework that runs cross platform. So what? Microsoft has done some cross platform stuff in the past and ditched it. I don't see that happening in this case however. I think Microsoft is finally starting to come around on the fact that Windows, while holding a massive amount of the market share, is not the end-all-be-all when it comes to things like... the internet. Microsoft is realizing that it is time to start competing against people like Adobe/Macromedia who have ruled the internet for quite a while now, who have gotten so cocky with their market share on the internet side of things that they have started working toward a desktop takeover. The other nice little inclusion with Silverlight is the DLR or Dynamic Language Runtime. The DLR allows Ruby, Python and other traditionally NON-.Net languages to be compiled into IL code so that they can utilize the CLR. This is being done with respect to the language as well. i.e. Microsoft is not trying to assert their way of doing things into these community run languages, but rather are taking the accepted ways of doing things and incorporating those into the DLR. If that wasn't enough, Microsoft has released the DLR to the community so that it can be built upon and more languages can be added in over time. There are too many things to list here and to be honest, since I am not at Mix and am relying on News and Blog Postings to get all of my information, I am going to quit writing for the time being and go continue reading. I would highly recommend reading Scott Hanselman's post on the subject though I leave you with this: It is going to be interesting to watch what happens over the next year, between Adobe and Microsoft, things are going to move even further off of the desktop and this is going to cement the RIA into the mainstream environment. I am not going to say that one technology is better than the other at this point and I am going to concentrate on learning both Flex/Apollo and Silverlight/WPF over the next few months so that I can be proficient in both, because much like the battle between BlueRay and HD-DVD, this is just getting started. Just don't write Microsoft off because they are behind. They aren't the underdog by any means. They've been sitting back and watching, silently plotting, and they've just made their move.