I have recently started developing webparts using Sharepoint 2007. Some *fun* things I have encountered along the way...
Styling in sharepoint was tricky, until I started using 960 Grid System
I wrote a method to take in either one or two controls, and a main div to hold them. Styles for the control divs can also be passed.
I then wrapped each control in a div, gave it the gs class it needed i.e. "grid_12" as well as any styles passed in.
Then I added these divs to a container div and returned this so it could be styled independently.
(Main Div Holds Container Div, which holds Control Divs.)
Friday, 3 September 2010
Links - Visual Studio Styles & Winmerge
http://studiostyles.info/
More visual studio styles. Like below....
Visual Studio, and SQL Server "High Contrast" Themes.
When developing, I like to use a high contrast theme as I think it's easier on the eyes.
There is a big list to choose from here...
http://www.hanselman.com/blog/VisualStudioProgrammerThemesGallery.aspx
I use Brad Wilson's theme.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I recently found that you can export these setting from VS to SQL MS. The utility below helps, just ensure that the registry keys are entered correctly - the default is vs2005 to sql2005, but there is help in the comments for changing these to vs2008 or sql2008.
http://winterdom.com/2007/10/colorschemesinsql2005managementstudio
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
As the merge tool included with VS is the worst piece of software ever written, I would recommend that you do as I have done and upgrade to use winmerge, which makes the process of merging in changes a lot more painless!
Get Winmerge here
In Visual Studio do the following:
Click on Tools menu
Click on Options menu item
Expand Source Control tree item
Select Visual Studio Team Foundation Server tree item
Click on Configure User Tools... button
Comparing
To use WinMerge as the Compare/Diff tool:
Click the Add... button
For Extension, type *
For Operation, select Compare
For Command, browse for C:\Program Files\WinMerge\WinMerge.exe
For Arguments, type /x /e /ub /wl /dl %6 /dr %7 %1 %2
Click OK to accept
Merging
To use WinMerge as the Merge tool:
Click the Add... button
For Extension, type *
For Operation, select Merge
For Command, browse for C:\Program Files\WinMerge\WinMerge.exe
For Arguments, type /x /e /ub /wl /dl %6 /dr %7 %1 %2 %4
Click OK to accept
Info stolen from here:
http://www.neovolve.com/post/2007/06/19/using-winmerge-with-tfs.aspx
More visual studio styles. Like below....
Visual Studio, and SQL Server "High Contrast" Themes.
When developing, I like to use a high contrast theme as I think it's easier on the eyes.
There is a big list to choose from here...
http://www.hanselman.com/blog/VisualStudioProgrammerThemesGallery.aspx
I use Brad Wilson's theme.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I recently found that you can export these setting from VS to SQL MS. The utility below helps, just ensure that the registry keys are entered correctly - the default is vs2005 to sql2005, but there is help in the comments for changing these to vs2008 or sql2008.
http://winterdom.com/2007/10/colorschemesinsql2005managementstudio
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
As the merge tool included with VS is the worst piece of software ever written, I would recommend that you do as I have done and upgrade to use winmerge, which makes the process of merging in changes a lot more painless!
Get Winmerge here
In Visual Studio do the following:
Click on Tools menu
Click on Options menu item
Expand Source Control tree item
Select Visual Studio Team Foundation Server tree item
Click on Configure User Tools... button
Comparing
To use WinMerge as the Compare/Diff tool:
Click the Add... button
For Extension, type *
For Operation, select Compare
For Command, browse for C:\Program Files\WinMerge\WinMerge.exe
For Arguments, type /x /e /ub /wl /dl %6 /dr %7 %1 %2
Click OK to accept
Merging
To use WinMerge as the Merge tool:
Click the Add... button
For Extension, type *
For Operation, select Merge
For Command, browse for C:\Program Files\WinMerge\WinMerge.exe
For Arguments, type /x /e /ub /wl /dl %6 /dr %7 %1 %2 %4
Click OK to accept
Info stolen from here:
http://www.neovolve.com/post/2007/06/19/using-winmerge-with-tfs.aspx
Monday, 19 July 2010
Impersonating Users - e.g. For Unit Tests
http://platinumdogs.wordpress.com/2008/10/30/net-c-impersonation-with-network-credentials/
//---code below---
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Security.Principal;
namespace Tools.Network
{
public enum LogonType
{
LOGON32_LOGON_INTERACTIVE = 2,
LOGON32_LOGON_NETWORK = 3,
LOGON32_LOGON_BATCH = 4,
LOGON32_LOGON_SERVICE = 5,
LOGON32_LOGON_UNLOCK = 7,
LOGON32_LOGON_NETWORK_CLEARTEXT = 8, // Win2K or higher
LOGON32_LOGON_NEW_CREDENTIALS = 9 // Win2K or higher
};
public enum LogonProvider
{
LOGON32_PROVIDER_DEFAULT = 0,
LOGON32_PROVIDER_WINNT35 = 1,
LOGON32_PROVIDER_WINNT40 = 2,
LOGON32_PROVIDER_WINNT50 = 3
};
public enum ImpersonationLevel
{
SecurityAnonymous = 0,
SecurityIdentification = 1,
SecurityImpersonation = 2,
SecurityDelegation = 3
}
class Win32NativeMethods
{
[DllImport("advapi32.dll", SetLastError = true)]
public static extern int LogonUser( string lpszUserName,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int DuplicateToken( IntPtr hToken,
int impersonationLevel,
ref IntPtr hNewToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool RevertToSelf();
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool CloseHandle(IntPtr handle);
}
///
/// Allows code to be executed under the security context of a specified user account.
///
///
///
/// Implements IDispose, so can be used via a using-directive or method calls;
/// ...
///
/// var imp = new Impersonator( "myUsername", "myDomainname", "myPassword" );
/// imp.UndoImpersonation();
///
/// ...
///
/// var imp = new Impersonator();
/// imp.Impersonate("myUsername", "myDomainname", "myPassword");
/// imp.UndoImpersonation();
///
/// ...
///
/// using ( new Impersonator( "myUsername", "myDomainname", "myPassword" ) )
/// {
/// ...
/// [code that executes under the new context]
/// ...
/// }
///
/// ...
///
public class Impersonator : IDisposable
{
private WindowsImpersonationContext _wic;
///
/// Begins impersonation with the given credentials, Logon type and Logon provider.
///
///
Name of the user.
///
Name of the domain.
///
The password.
///
Type of the logon.
///
The logon provider.
public Impersonator(string userName, string domainName, string password, LogonType logonType, LogonProvider logonProvider)
{
Impersonate(userName, domainName, password, logonType, logonProvider);
}
///
/// Begins impersonation with the given credentials.
///
///
Name of the user.
///
Name of the domain.
///
The password.
public Impersonator(string userName, string domainName, string password)
{
Impersonate(userName, domainName, password, LogonType.LOGON32_LOGON_INTERACTIVE, LogonProvider.LOGON32_PROVIDER_DEFAULT);
}
///
/// Initializes a new instance of the class.
///
public Impersonator()
{}
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
public void Dispose()
{
UndoImpersonation();
}
///
/// Impersonates the specified user account.
///
///
Name of the user.
///
Name of the domain.
///
The password.
public void Impersonate(string userName, string domainName, string password)
{
Impersonate(userName, domainName, password, LogonType.LOGON32_LOGON_INTERACTIVE, LogonProvider.LOGON32_PROVIDER_DEFAULT);
}
///
/// Impersonates the specified user account.
///
///
Name of the user.
///
Name of the domain.
///
The password.
///
Type of the logon.
///
The logon provider.
public void Impersonate(string userName, string domainName, string password, LogonType logonType, LogonProvider logonProvider)
{
UndoImpersonation();
IntPtr logonToken = IntPtr.Zero;
IntPtr logonTokenDuplicate = IntPtr.Zero;
try
{
// revert to the application pool identity, saving the identity of the current requestor
_wic = WindowsIdentity.Impersonate(IntPtr.Zero);
// do logon & impersonate
if (Win32NativeMethods.LogonUser(userName,
domainName,
password,
(int)logonType,
(int)logonProvider,
ref logonToken) != 0)
{
if (Win32NativeMethods.DuplicateToken(logonToken, (int)ImpersonationLevel.SecurityImpersonation, ref logonTokenDuplicate) != 0)
{
var wi = new WindowsIdentity(logonTokenDuplicate);
wi.Impersonate(); // discard the returned identity context (which is the context of the application pool)
}
else
throw new Win32Exception(Marshal.GetLastWin32Error());
}
else
throw new Win32Exception(Marshal.GetLastWin32Error());
}
finally
{
if (logonToken != IntPtr.Zero)
Win32NativeMethods.CloseHandle(logonToken);
if (logonTokenDuplicate != IntPtr.Zero)
Win32NativeMethods.CloseHandle(logonTokenDuplicate);
}
}
///
/// Stops impersonation.
///
private void UndoImpersonation()
{
// restore saved requestor identity
if (_wic != null)
_wic.Undo();
_wic = null;
}
}
}
//---code below---
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Security.Principal;
namespace Tools.Network
{
public enum LogonType
{
LOGON32_LOGON_INTERACTIVE = 2,
LOGON32_LOGON_NETWORK = 3,
LOGON32_LOGON_BATCH = 4,
LOGON32_LOGON_SERVICE = 5,
LOGON32_LOGON_UNLOCK = 7,
LOGON32_LOGON_NETWORK_CLEARTEXT = 8, // Win2K or higher
LOGON32_LOGON_NEW_CREDENTIALS = 9 // Win2K or higher
};
public enum LogonProvider
{
LOGON32_PROVIDER_DEFAULT = 0,
LOGON32_PROVIDER_WINNT35 = 1,
LOGON32_PROVIDER_WINNT40 = 2,
LOGON32_PROVIDER_WINNT50 = 3
};
public enum ImpersonationLevel
{
SecurityAnonymous = 0,
SecurityIdentification = 1,
SecurityImpersonation = 2,
SecurityDelegation = 3
}
class Win32NativeMethods
{
[DllImport("advapi32.dll", SetLastError = true)]
public static extern int LogonUser( string lpszUserName,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int DuplicateToken( IntPtr hToken,
int impersonationLevel,
ref IntPtr hNewToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool RevertToSelf();
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool CloseHandle(IntPtr handle);
}
///
/// Allows code to be executed under the security context of a specified user account.
///
///
///
/// Implements IDispose, so can be used via a using-directive or method calls;
/// ...
///
/// var imp = new Impersonator( "myUsername", "myDomainname", "myPassword" );
/// imp.UndoImpersonation();
///
/// ...
///
/// var imp = new Impersonator();
/// imp.Impersonate("myUsername", "myDomainname", "myPassword");
/// imp.UndoImpersonation();
///
/// ...
///
/// using ( new Impersonator( "myUsername", "myDomainname", "myPassword" ) )
/// {
/// ...
/// [code that executes under the new context]
/// ...
/// }
///
/// ...
///
public class Impersonator : IDisposable
{
private WindowsImpersonationContext _wic;
///
/// Begins impersonation with the given credentials, Logon type and Logon provider.
///
///
Name of the user.
///
Name of the domain.
///
The password.
///
Type of the logon.
///
The logon provider.
public Impersonator(string userName, string domainName, string password, LogonType logonType, LogonProvider logonProvider)
{
Impersonate(userName, domainName, password, logonType, logonProvider);
}
///
/// Begins impersonation with the given credentials.
///
///
Name of the user.
///
Name of the domain.
///
The password.
public Impersonator(string userName, string domainName, string password)
{
Impersonate(userName, domainName, password, LogonType.LOGON32_LOGON_INTERACTIVE, LogonProvider.LOGON32_PROVIDER_DEFAULT);
}
///
/// Initializes a new instance of the
///
public Impersonator()
{}
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
public void Dispose()
{
UndoImpersonation();
}
///
/// Impersonates the specified user account.
///
///
Name of the user.
///
Name of the domain.
///
The password.
public void Impersonate(string userName, string domainName, string password)
{
Impersonate(userName, domainName, password, LogonType.LOGON32_LOGON_INTERACTIVE, LogonProvider.LOGON32_PROVIDER_DEFAULT);
}
///
/// Impersonates the specified user account.
///
///
Name of the user.
///
Name of the domain.
///
The password.
///
Type of the logon.
///
The logon provider.
public void Impersonate(string userName, string domainName, string password, LogonType logonType, LogonProvider logonProvider)
{
UndoImpersonation();
IntPtr logonToken = IntPtr.Zero;
IntPtr logonTokenDuplicate = IntPtr.Zero;
try
{
// revert to the application pool identity, saving the identity of the current requestor
_wic = WindowsIdentity.Impersonate(IntPtr.Zero);
// do logon & impersonate
if (Win32NativeMethods.LogonUser(userName,
domainName,
password,
(int)logonType,
(int)logonProvider,
ref logonToken) != 0)
{
if (Win32NativeMethods.DuplicateToken(logonToken, (int)ImpersonationLevel.SecurityImpersonation, ref logonTokenDuplicate) != 0)
{
var wi = new WindowsIdentity(logonTokenDuplicate);
wi.Impersonate(); // discard the returned identity context (which is the context of the application pool)
}
else
throw new Win32Exception(Marshal.GetLastWin32Error());
}
else
throw new Win32Exception(Marshal.GetLastWin32Error());
}
finally
{
if (logonToken != IntPtr.Zero)
Win32NativeMethods.CloseHandle(logonToken);
if (logonTokenDuplicate != IntPtr.Zero)
Win32NativeMethods.CloseHandle(logonTokenDuplicate);
}
}
///
/// Stops impersonation.
///
private void UndoImpersonation()
{
// restore saved requestor identity
if (_wic != null)
_wic.Undo();
_wic = null;
}
}
}
Code Coverage. Signed Assembly.
(Exception from HRESULT: 0x8013141A) ---> System.Security.SecurityException: Strong name validation failed. (Exception from HRESULT: 0x8013141A)
I had a problem with code coverage on a singed assembly, and the link below helped me...
http://weblogs.asp.net/soever/archive/2005/07/23/420338.aspx
VS.NET 2005: Code coverage for signed assemblies I am currently working on an application using VS.NET 2005, and because all the TDD tools like unit testing and code coverage are available I started to use them.
When I started code coverage on my signed application I got the following exception:
Test method X threw exception: System.IO.FileLoadException: Could not load file or assembly 'Y, Version=1.0.0.0, Culture=neutral, PublicKeyToken=Z' or one of its dependencies. HRESULT: 0x8013141A Strong name validation failed. ---> System.Security.SecurityException: Exception from HRESULT: 0x8013141A Strong name validation failed at X.
Not so strange if you think about it. Assembly is signed, code coverage needs code instrumentation, means modifications of the assembly, resulting in incorrect assembly so the validation failed.
Solution is to resign the assembly after instrumentation.
If you open the localtestrun.testrunconfig file (or something similar) in your solution items (double-click it), you can enable resigning in the Code Coverage section. This solves the problem.
I had a problem with code coverage on a singed assembly, and the link below helped me...
http://weblogs.asp.net/soever/archive/2005/07/23/420338.aspx
VS.NET 2005: Code coverage for signed assemblies I am currently working on an application using VS.NET 2005, and because all the TDD tools like unit testing and code coverage are available I started to use them.
When I started code coverage on my signed application I got the following exception:
Test method X threw exception: System.IO.FileLoadException: Could not load file or assembly 'Y, Version=1.0.0.0, Culture=neutral, PublicKeyToken=Z' or one of its dependencies. HRESULT: 0x8013141A Strong name validation failed. ---> System.Security.SecurityException: Exception from HRESULT: 0x8013141A Strong name validation failed at X.
Not so strange if you think about it. Assembly is signed, code coverage needs code instrumentation, means modifications of the assembly, resulting in incorrect assembly so the validation failed.
Solution is to resign the assembly after instrumentation.
If you open the localtestrun.testrunconfig file (or something similar) in your solution items (double-click it), you can enable resigning in the Code Coverage section. This solves the problem.
Thursday, 20 May 2010
JQuery, first foray into...
Doing some jquery stuff.
Wanted to make a cool warning message, to users that ran on page load.
I found these links very helpful
http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html
http://yensdesign.com/2008/09/how-to-create-a-stunning-and-smooth-popup-using-jquery/
http://www.yourhtmlsource.com/javascript/cookies.html
Wanted to make a cool warning message, to users that ran on page load.
I found these links very helpful
http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html
http://yensdesign.com/2008/09/how-to-create-a-stunning-and-smooth-popup-using-jquery/
http://www.yourhtmlsource.com/javascript/cookies.html
Wednesday, 25 November 2009
First Post: Useful Links for me this week.
While testing a secure site in IE8, I noticed a problem in displaying Secure/Un-secure elements of the page. I was able to test this locally without having IE8 installed by using Browser Sandbox
Unit testing a class which contained private methods. I could not access them from the unit test class, without adding the following line to the assemblyinfo.cs file for the project being tested.
[assembly: InternalsVisibleTo("MyUnitTests")]
I also had to change the method declarations in this class to use internal instead of private. This information was gathered from this link
Unit testing a class which contained private methods. I could not access them from the unit test class, without adding the following line to the assemblyinfo.cs file for the project being tested.
[assembly: InternalsVisibleTo("MyUnitTests")]
I also had to change the method declarations in this class to use internal instead of private. This information was gathered from this link
Subscribe to:
Posts (Atom)