Mark's Stuff

My Foray Into Weblogging. Using this to store interesting items for later review.

Wednesday, June 24, 2009

Tip: Get the name of the calling method

Very handy for using common logging or exception handling routines.

This code is corrected from original article, and added to also get the calling function.

using System.Diagnostics;

void Log(string eventMessage)
{

   Console.WriteLine("Event logged by " + (new StackTrace().GetFrame(1).GetMethod().Name);
Console.WriteLine("Module: " + (new StackTrace().GetFrame(1).GetMethod().Module.Name)



   Console.WriteLine("Event: " + eventMessage);

}



Tips & Tricks for ASP.NET, IIS, and Visual Web Developer : Tip #83: Did you know... You can get the name of the calling method from the stack using reflection?

Labels: ,

Wednesday, June 17, 2009

ADO.NET team: System.Data.OracleClient Deprecated

Microsoft ADO.Net team (Himanshu Vasishth, Program Manager) announces that the ADO.Net Oracle provider will no longer be supplied by Microsoft.  Recommended to use 3rd party provider.

ADO.NET team blog : System.Data.OracleClient Update

Possible alternatives are:

Labels:

Monday, June 15, 2009

Interesting problem: IIS file download = 0 bytes

I ran into an interesting problem at a client site the other day.  Another developer group had written and installed a ASP.Net application (Visual Studio 2008, .Net Framework 3.5 SP1, Windows Server 2003 R2, SQL Server 2005).  Without divulging too many details, let's just say the application had a public site where users could upload a file, and an internal admin site where the internal user could download the file.  The file is being stored in the database in a varbinary(max) column.

After the sites were installed, the internal user had a problem downloading the file; it always came back as 0 bytes.  It did not matter the file type (pdfs and word docs were used), browser type (same for IE6 (standard for company), IE7, IE8, Firefox 3.x, Chrome, Opera , Safari on Windows).  The file was definitely in the database, and the original developer wrote a Windows desktop app to download the file as a temporary workaround.  The original developer swore the file download it worked just fine on their servers, and brought in a more experienced consultant to try to help diagnose the problem.  I was at this client site on another project, and was asked to take a look to see if I could spot anything.

After a few false starts doing some troubleshooting (the original developer said the VS project was a web site project, and had the code-behind files in the web directory, so we would modify the .cs file to try to track the problem, but had no results; turns out it was a web application project, and we were not recompiling the project), we did confirm the byte array from the database field was being populated.  The code was using Response.BinaryWrite, and seemed to be setting the proper headers and sending the data.  We look at the IIS web site settings over and over, trying to find some clue. 

The server the web application was installed on did have other live applications running, so our debugging the production server was limited so as to not affect the other apps. Our next attempt was to setup another Windows IIS server (virtual, on MS Virtual Server) and install the web site app on there.  The file download worked just fine there.  So it appears that the application is OK, it must be an IIS setting causing the problem.  Now that we had a server we knew it worked on, I took the metabase.xml files from both servers and worked to compare them.

That was when I saw the problem: HTTP Compression was turned on the first server.  We had missed it on the IIS Settings because that (the "Service" tab) is only on the property dialog for the Web Sites folder, not on the web sites themselves, and not on the server settings.  Here is the dialog window:

clip_image002

Turning that off did solve the download file problem, but the client was uneasy about turning it off (understandably) since it was likely turned as part of the other applications that was running on that server, and they did not want to risk that apps.

Although I knew it would not affect the other apps to turn off HTTP compression, I looked further into it and saw that HTTP compression can be turned on or off for the entire server, by web site, by directory, by file type, or by individual page, all by using adsutil commands.  I also found a .cmd file in the AdminScript directory of the server turning on HTTP compression, so I modified it to turn off compression for the web site:

CSCRIPT.EXE ADSUTIL.VBS SET W3SVC/Filters/Compression/GZIP/HcScriptFileExtensions "asp" "dll" "exe" "pdf" "aspx" "svc"
CSCRIPT.EXE ADSUTIL.VBS SET W3SVC/Filters/Compression/DEFLATE/HcScriptFileExtensions "asp" "dll" "exe" "pdf" "aspx" "svc"
CSCRIPT.EXE ADSUTIL.VBS SET W3SVC/Filters/Compression/GZIP/HcDynamicCompressionLevel 9
CSCRIPT.EXE ADSUTIL.VBS SET W3SVC/Filters/Compression/DEFLATE/HcDynamicCompressionLevel 9
CSCRIPT.EXE ADSUTIL.VBS SET W3SVC/Filters/Compression/GZIP/HcStaticCompressionLevel 9
CSCRIPT.EXE ADSUTIL.VBS SET W3SVC/Filters/Compression/DEFLATE/HcStaticCompressionLevel 9
CSCRIPT.EXE ADSUTIL.VBS SET w3SVC/Filters/Compression/Parameters/HcDoDynamicCompression true 
CSCRIPT.EXE ADSUTIL.VBS SET w3SVC/Filters/Compression/Parameters/HcDoStaticCompression true 
REM Added exclusion for careeradmin site; mark harr; 6/3/2009
CSCRIPT.EXE ADSUTIL.VBS SET W3SVC/2129524648/root/DoDynamicCompression false

That solved the issue.  But there were a couple other interesting things:



  • I first looked to turn off compression for just the file types (pdf, etc), but it turns out that IIS determines if compression will be done based on the requested file suffix, not the response headers. So since the file was downloaded from a postback to index.aspx, turning off compression on pdf did not have any affect.

  • Then I looked to turn off just for the page doing the download. But since the site was built with a single page (index.aspx) and loading different custom controls (ascx), I could not differentiate the page for IIS.

  • So I just turned off http compression for the admin site.  Figure that was not bad, since the site will only be accessed internally, and not likely over the internet, the lack of http compression will not be an issue.

  • After I finished this, I came up with the thought that perhaps adding a "Response-encoding: gzip" header with the file download may have also solved the problem.  IIS may have already setup that header when it determined it was doing http compression, and the code may have been clearing that header when it did the Response.Clear command before setting up its BinaryWrite.  But the code putting that header would need to ensure that compression was happening and only add the encoding header when desired.  Sometime when I have a few hours to look at that, I will see if that technique will work.

Labels: , ,

Friday, June 12, 2009

Using Windows 7 and Vista features in .Net code


Just released from Microsoft:

Windows� API Code Pack for Microsoft� .NET Framework (v0.90) - Home

Vista Bridge Sample Library 1.4

Some of the newer features in Vista and Windows 7 are not exposed in the .Net Framework (yet).  This package of source code from Microsoft shows how to access and use these features from managed code.  Some of the features here are:

Windows 7 Taskbar Jump Lists, Icon Overlay, Progress Bar, Tabbed Thumbnails, and Thumbnail Toolbars.

Known Folders, Windows 7 Libraries, non-file system containers, and a hierarchy of Shell Namespace entities.

Windows 7 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.

Labels: , , ,

Friday, June 05, 2009

SEO on Dynamic Pages

 

SEO on Dynamic Pages - URL rewrites, 301 Redirects, and more SEO on Dynamic Pages

Good article on enhancing SEO on catalog and other dynamic pages.

Labels: