Friday, June 25, 2010

IE8 security warning when mixing http and https content

Ran into an issue with IE8 showing the following prompt with every page view under SSL.

Security Warning
Do you want to view only the webpage content that was delivered securely?
This webpage contains content that will not be delivered using a secure HTTPS
connection, which could compromise the security of the entire webpage.

Turns out the addition of the Microsoft AJAX CDN service is the cause in this particular case. Changing the script link to use SSL resolves the issue.

Wednesday, June 23, 2010

Programmatic log4net configuration at runtime

I've been looking for a way to enable/disable a log4net appender at runtime through code. Doing so would remove the need to remote to the production web server to alter the logging config file.

The blog post Tweaking log4net Settings Programmatically has a extension method to perform actions on certain types of appender.

Tuesday, June 22, 2010

Visual Studio 2010 CSS colour picker

Came across a Colour picker dialog for use when editing CSS files in the Visual Studio 2010 editor.

Right click on the style and select Build Style or
Styles (Menu) > Build Style

Thursday, June 17, 2010

Disabling a Trigger for a LINQ to SQL DataContext

I have a trigger on a table that fires on updates and adds a record to another table indicating that it needs to be rolled up to an external system. In a few cases I need to dynamically suppress this trigger to prevent circular updates between the two systems. My data access is via LINQ to SQL for the system in question.

The article Disabling a Trigger for a Specific SQL Statement or Session deals with the same problem.

using(DbDataContext dc = new DbDataContext())
{
 //Update fields etc...

 dc.Connection.Open();
 //Set the context_info here within the open connection so that it is in-scope 
 //for the triggers
 dc.ExecuteCommand("SET Context_Info 0x55555");
 dc.SubmitChanges();
 dc.Connection.Close();
}
 CREATE TRIGGER TR_Mock ON dbo.TableForTrigger FOR UPDATE
 AS 
 DECLARE @Cinfo VARBINARY(128) 
 SELECT @Cinfo = Context_Info() 
 IF @Cinfo = 0x55555 
 RETURN 
 PRINT 'Trigger Executed' 
 -- Actual code goes here
GO  

See Also:

Wednesday, June 16, 2010

ASP.NET Check if the current user can access a URL/Page

A method to verify that the user from the current HttpContext has sufficient roles to access a URL identified from the SiteMap.

  /// 
  /// Can the current User access the given URL according to the SiteMap (role trimmed)
  /// 
  /// URL to check. Can start with ~. Should not include query string parameters.
  /// True if the user has access.
  public static bool CanAccessUrl(string url)
  {
   SiteMapProvider provider = SiteMap.Provider;
   HttpContext current = HttpContext.Current;
   string rawUrl = VirtualPathUtility.ToAbsolute(url);
   SiteMapNode node = provider.FindSiteMapNode(rawUrl);
   return (node != null &&
    provider.IsAccessibleToUser(HttpContext.Current, node));
  }

Friday, June 11, 2010

TFS - Undo Checkout of Unmodified files

I've added a handy console command from the Team Foundation Server Power Tools to the end of our code generation batch file to undo checkouts on any file that hasn't actually changed.

This way the code generator can work blindly off the data source and the change set only contains the files that have actually changed.

tfpt uu "C:\Development\ProjectRoot" /noget /recursive

See also:

Thursday, June 10, 2010

Nelson .NET User Group Presentation - Common TSQL Programming Mistakes - 25th of June

Upcoming presentation

Dave Dustin from the AucklandSQL user group will be giving a presentation on TSQL.

Title:
Common TSQL Programming Mistakes

Abstract:
We are going to examine a variety of mistakes to which many developers fall prey - some obvious, some fairly subtle and some just plain evil! Coupled with this, we’ll be investigating some simple, and some not so, tips for increasing performance from your data layer.

Useful links:

When:
Friday 25th June 2010
Gather at 11:50 am, starting at 12:00 pm.
Approximately 1 hour plus pizza afterwards.

Where:
FuseIT Ltd,
Ground Floor,
7 Forests Rd,
Stoke,
Nelson
(Off Nayland Rd and behind Carters)

http://local.live.com/default.aspx?v=2&cp=-41.299774~173.236231&style=r&lvl=16&alt=-1000
or
http://maps.google.com/?ie=UTF8&om=1&z=17&ll=-41.299774,173.236231&spn=0.005239,0.010042&t=h

If you are parking on site, please use the parks marked FuseIT that are at the back of the site.

Catering: Pizza & Drinks
Door Charge: Free

RSVP to me if you are going to attend so I can guesstimate the food and drink requirements.

However, feel free to turn up on the day though if you can't commit at the moment.

Please feel free to invite anyone who may be interested in attending.

Wednesday, June 9, 2010

Codec packs

These are based on the open source ffdshow project and will add support for VP6-encoded Flash (.flv) files, H.264 video in the Matroska (.mkv) container, and Ogg (.ogg) video files to Windows Media Player.

See Also:

Tuesday, June 8, 2010

Changing the Compare/diff tool used in VS2010

Tools > Options > Source Control - Visual Studio Team Foundation Service > Configure User Tools...

For both Compare and Merge I've set the extension to .*.

Compare Arguments for DiffMerge: /title1=%6 /title2=%7 %1 %2

Merge Arguments for DiffMerge: /title1=%6 /title2=%8 /title3=%7 /result=%4 %1 %3 %2


Diffing Word Documents

Better yet, you can configure TFS to Diff Word documents.

Save the diff-doc.js somewhere convenient and reference it as the Command. Then give it the Arguments %1 %2


See Also:

Sunday, June 6, 2010

Gotchas when upgrading from VS2008 to VS2010

Ran into a few issues when upgrading a solution with 26 projects from Visual Studio 2008 to Visual Studio 2010.

I started by creating a new solution file to be used by VS2010 and added the existing projects.

Issue 1 - Referencing a higher framework version

VS2008 was fairly accepting of a framework 2.0 project referencing DLL's or projects with a higher framework target.

VS2010 will stop the build with a error like:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3268: The primary reference "newerFrameworkProject, Version=18.0.0.0, Culture=neutral, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "newerFrameworkProject, Version=18.0.0.0, Culture=neutral, processorArchitecture=MSIL" or retarget your application to a framework version which contains "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" and errors that all the functions/types used in the api dll are not defined.

In this case adding <SpecificVersion>true</SpecificVersion> to the reference resolves the issue.

See Also

Issue 2 - Project ToolsVersion

The ToolsVersion attribute on the Project node is changed from 3.5 to 4.0 by the upgrade wizard.

Before
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
After
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">

Since our TFS build server hasn't been updated yet I needed to revert this in the TFSBuild.proj

Issue 3 - Microsoft.WebApplication.targets path

The project import for Microsoft.WebApplication.targets differs for VS2010. See Working with both VS 2010 and 2008 on the team for a solution using conditional statements.

Issue 4 - System.Web.Security provider types have been forwarded to System.Web.ApplicationServices

See System.Web.MembershipProvider and RoleProvider references not found in unit tests after VS2010 upgrade