Tuesday, March 25, 2008

Visual Studio 2008 HotFix and VB HotFix

A HotFix for VS2088 was released early in February that addresses several issues reported with Web Applications. A list of the fixed bugs can be seen on ScottGu's Blog. You can download the hot fix here.

Also, 2 days ago, the Visual Basic team released a HotFix that solves some performance issues in VS2008. Download it here


Monday, March 24, 2008

App_Offline Goodness

ASP.NET 2.0 comes with this built-in feature to easily bring down an Web Application, make changes to it and reload the application back again.

It's as easy as uploading an App_Offline.htm file in the root of your Web Application directory and you are done. Include any "under construction" or "maintenance" messages in the App_Offline.htm file that you want to display to your end users.

Once you are done, simply delete the file and ASP.NET will reload the application and everything is back to normal. For detailed info check ScottGu's blog.

Friday, March 21, 2008

Server.HtmlEncode vs HttpUtility.HtmlEncode

Have you ever wonder why there is an Html Encoding function (and other similar functions) in 3 different objects and namespaces?
The most common one is Server.HtmlEncode or System.Web.HttpContext.Current.Server.HtmlEncode.  The Server Object is an instance of the System.Web.HttpServerUtility Class and it is readily accessible through any .aspx page since they inherit from the Page object which in turn has a Server Object instance.  The second HtmlEncode function lives under System.Web.HttpUtility.  This class is basically a static version of the Server class which means that you could call the HtmlEncode function from a static function or call from another class that does not have an instance of the HttpServerUtility class. Finally,  The third HtmlEncode function is located in the Microsoft's AntiCross-Site Scripting Library. In contrast with the Server.HtmlEncode and HttpUtility.HtmlEncode functions, the later function takes a more aggressive approach by using a white-list filtering instead of a black-list.
Hope this helps.

Wednesday, March 28, 2007

Sarcastic Wednesday!!!

You guys should check this out:

Sarcastic Wednesday

Hilarious. You will thank me later..

C# and VB together?

I have an app in VS 2005 that contains both VB and C# code in the same website project. At compile time I kept getting this error:

"The files '/WebSite/App_Code/VB/test.vb' and '/WebSite/App_Code/CS/test.cs' use a different language, which is not allowed since they need to be compiled together."

To go around this issue, simply add the following to your web.config file under the compilation tag:

&ltcodeSubDirectories>
&ltadd directoryName="CS">
&ltadd directoryName="VB">


In this case, all the VB files and C# files were already separated into different folders inside the App_Code Folder.

Hope this helps.

Tuesday, March 27, 2007

A look at security vulnerabilities in web software

This is a must see video for any web developer. Mike Andrews, does an awesome job at explaining how web applications can be attacked, how common these security vulnerabilities are, and how to go about improving protection against them.

Click Here if video doesn't start

Getting Serious

It's been a while since I last blogged about anything, so I decided to get serious and start blogging at least once a week, even if I rant about how much my blogs sucks :). Hopefully I'll have enough interesting things to say, so hopefully I'll get accustomed to the world of blogging. soon enough

Thursday, August 10, 2006

FTP in .Net 2.0

So I needed to write a simple function that would download a file from an Ftp location. After googling a little, I found MSN's sample code for FTP using the new FTP classes in 2.0. Here is a link to the Microsoft Download Page. After testing it out and changing the code to my needs, it worked pretty good, except that it only worked for text files. Binary files were being downloaded but the data was corrupt. I tried different things to get it to work like using a BinaryReader and Writer but I kept getting a corrupt file. Finally, I got it to work by including a single line:

ftpRequest.UseBinary = true;

So here is a basic skeleton of how to download a binary file from an FTP location:

//Create the Request Object

FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create("the FTP URI");
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
ftpRequest.UseBinary = true;

//Now we create a response object and ge the response stream

FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
Stream responseStream = ftpResponse.GetResponseStream();

//Create the destination File

FileStream DestFile = new FileStream("your file name here", FileMode.OpenOrCreate, FileAccess.ReadWrite);

//Reading the response stream and writing it to the destination file

try
{
byte[] myBuffer = new byte[2048];
int stream= 0;
do
{
stream= responseStream.Read(myBuffer , 0, myBuffer .Length);
DestFile.Write(myBuffer , 0, stream);
}
while (!(stream== 0));
}
catch (Exception ex)
{
//handle your exception here
finally
{
DestFile.Close();
}

If the method returns something, you could return the FtpCode:

return ftpResponse.StatusCode;

I Guess the file writing part could still be implemented using the BinaryReader and Writer objects, but this way worked out for me.

Wednesday, January 25, 2006

Ajax Revolution

I've been reading about Ajax (Asynchronous JavaScript + XML) and it seems to me like this technique is going to be the way to go for Web Application Developers. The best examples out there are Google Maps and Google Suggest. Basically Ajax lets developers create interactive web user interfaces that are comparable to desktop interfaces. Now developers can make requests to the server without having to reload the page and therefore getting rid of the clunkiness. Another advantage is that we get to to work with XML documents.

For .Net developers, more details about Ajax.Net can be found in the msdn library.
Here is a good article "Very Dynamic Web Interfaces" explaining Ajax with code samples.

A lot of big companies are switching their applications into Ajax. Even Microsoft's new version of hotmail will be heavily based on Ajax and Yahoo's new beta mail already uses Ajax. Other nice applications using this technolgy are ThinkFree and Writely.

Monday, January 23, 2006

First Post

Following the wise advice of a good friend of mine, I started this blog to record my discoveries and adventures about the everyday new and challenging tools for Web Software Development.
I've been programming in .Net for a few months now and I am swallowing waves of information and learning as much as I can as fast as I can. I am very interested in Agile development, especially the Crystal Clear methodology and Xtreme Programming. I am learning and implementing Agile processes in my current job in the hopes that soon these techniques will start to pay off.