Thursday, December 17, 2009

Session state can only be used when enableSessionState is set to true

I received this strange error out of the blue. My first guess was that there was something wrong with Visual Studio, so closing it and rebooting my machine worked. I was pretty sure this would work because my code changes were minimal (not enough to cause any errors).

Monday, October 12, 2009

Cross domain HTTP Request using JavaScript

My first choice was to use JQuery. You can use jQuery.ajax with dataType="jsonp". However, this won't work unless the servers supports jsonp (http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/). Cross domain HTTP requests are a really interesting topic.

After several tries, I decided to do this using ASP.NET (in the code-behind page):

Uri uri = new Uri("http://192.168.0.1/default/query");

if (uri.Scheme == Uri.UriSchemeHttp)

{

WebRequest request = HttpWebRequest.Create(uri);

request.Method = WebRequestMethods.Http.Get;

WebResponse response = request.GetResponse();

StreamReader reader = new StreamReader(response.GetResponseStream());

return reader.ReadToEnd();

}

Saturday, October 3, 2009

Filtering columns with NULL values in ADO.NET

In order to return columns with null values from a DataTable, use this expression:

"Isnull(Col1,'Null Column') = 'Null Column'"

If you need more information about filtering data, check out http://www.akadia.com/services/dotnet_filter_sort.html

Tuesday, September 22, 2009

Converting a string into an Enum

To convert a string into an Enum:

myClass.GeomType = (Display.GeomType)Enum.Parse(typeof(Display.GeomType), myGeomType.ToString(), true);

To convert an Enum into a string:

string test = myClass.GeomType.ToString();

Sunday, September 20, 2009

Google Analytics/Google Webmaster Tools

A while ago I started using Google Analytics. It was really easy to set up, and it gives you useful information, like:

1) site usage statistics
2) visitor profile information (like location)
3) browser used
4) Navigation analysis

OK, I agree this is information that you could retrieve with other commercial software. However, Google Analytics provides you with easy-to-read reports, and it's free (of course, you should be willing to share the collected information with Google). You can even build custom reports!!

In fact, I just read something about Google Webmaster Tools. I'll give it a try!

Saturday, September 12, 2009

JayRock vs AjaxPro

Personally, I prefer AjaxPro. It gives you the flexibility of passing a dataset, and it also provides you a cleaner way to wrap the data you want to pass around. Check out AjaxPro here.

Passing custom classes to a web service

This article can help you: http://www.dalepreston.com/Blog/2005/02/passing-classes-from-webservices-part.html

Basically, you need to do the following in the file Refence.cs:

1) Delete any references to XmlIncludeAttribute
2) Qualify your classes with the correct namespace (if necessary)
3) Remove the custom class declaration (I had to do this since I already had the class defined in my VS solution. In other words, I had access to the custom class in both the client and server application).

The other option is to write the proxy classes yourself, but I didn't try this.

Thursday, September 10, 2009

Overloading web methods in Visual Studio 2005

It's really simple, you just need to replace

WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

with

[WebServiceBinding(ConformsTo = WsiProfiles.None)]
I found this information here.

Saturday, June 20, 2009

More on CC.NET

CC.NET is a really cool technology. Now that I have it running, I don't have to worry or spend time creating installers. It can do everything: compile your VS solution, run automated tests, obfuscate and lock the assemblies, and create an installer.

But what happens when you try to use CC.NET with a solution that has managed and unmanaged code (and more important, does not contain explicit dependencies between some projects)? The problem is that deven.com will not compile the projects in the solution in the correct build order. Eventually you will have to fix the VS solution and set up the correct dependencies, but there is a workaround. Just create a task for each project and CC.NET will compile the projects in that order. The drawback is that you may end up with quite a few tasks, depending on your project.

Wednesday, June 17, 2009

Setting up Cruise Control .NET

So I was setting up this application, which is really easy to do. I'd like to post some useful configuration snippets:

1) Adding several SVN repositories







2) Setting up several tasks










You can find more information on their website, but I found that some sections are not up-to-date.

Friday, April 24, 2009

Cross-thread operation not valid: Control 'Ctrl' accessed from a thread other than the thread it was created on

I though I would have to redesign part of the application, after all, this seems like a critical error. But if you come across this error, check out this link:

http://www.vcskicks.com/cross-thread.php

Delegates can fix it. The code below will help you (part of this code is from the website above).

 
private delegate void AddListBoxItemDelegate(object item);
... then copy this code inside your method...
if (this.InvokeRequired)
{
AddListBoxItemDelegateaddItemDel = new AddListBoxItemDelegate
(AddListBoxItem); //delegate
object[] parameters = { text }; //parameters
this.Invoke(addItemDel, parameters); //call
}

else

{
//code you want to execute
}

Saturday, January 3, 2009

Disabling controls during a postback

Have you ever wondered how to disable the controls in the UI when doing a postback? This is a way to give feedback to the user saying: "wait for the page to load/respond". There are other ways to give this kind of feedback, for example, by using a busy indicator. The article "Managing the User Experience in AJAX" shows how to handle the first situation:

msdn.microsoft.com/en-us/magazine/cc163319.aspx