Friday, October 06, 2006
10/6/2006 11:44:16 AM (Mitteleuropäische Sommerzeit , UTC+02:00)  #    Disclaimer  |  Comments [0]  | 
 Thursday, September 28, 2006

Syntax 1

To add a column to an existing table, the ALTER TABLE syntax is:

ALTER TABLE TableName
 ADD ColumnName column-definition;

For example:

ALTER TABLE yourtable
 ADD yourcolumn  varchar2(50);

This will add a column called yourcolumn to the yourtable table.


Syntax 2

To add multiple columns to an existing table, the ALTER TABLE syntax is:

ALTER TABLE TableName
ADD ( column1 column-definition,
column2 column-definition,
...
columnn column_definition );

For example:

ALTER TABLE yourtable
ADD ( yourcolumn1 varchar2(50),
yourcolumn2 varchar2(45) );

This will add two columns (yourcolumn1 and yourcolumn2) to the yourtable table.

9/28/2006 2:00:16 PM (Mitteleuropäische Sommerzeit , UTC+02:00)  #    Disclaimer  |  Comments [0]  | 
 Monday, August 07, 2006

Use System.Web.HttpUtility.UrlEncode or the convenient way "Server.UrlEncode" inside an .aspx page.

8/7/2006 4:37:41 PM (Mitteleuropäische Sommerzeit , UTC+02:00)  #    Disclaimer  |  Comments [0]  | 
 Saturday, July 15, 2006

Anwendungsfall:

Ein Objekt soll dynamisch um einzelne Funktionalitäten oder Zuständigkeiten erweitert werden. Diese Funktionalitäten sind beliebig kombinierbar. Decorator können als Altnerative für lange Vererbungsketten angesehen werden, bleiben dabei aber viel flexibler als Hierarchien.

Beispiele für die Anwendung:

UI-Elemente sollten je nach Verwendungszweck verschiedene zusätzliche Funktionalitäten oder Eigenschaften implementieren (Beispiel WebUserControls: einfacher Hyperlink, Hyperlink mit Contextmenü, Hyperlink mit JavaScript Funktionen)

Grafische Darstellung:

Beispielcode:

public partial class _Default : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {
      IExtendedControl c0 = new SimpleLabel();
      c0.Draw(Response);


      Response.Write("<br>");

      IExtendedControl c1 = new LableExtension1(new SimpleLabel());
      c1.Draw(Response);

      Response.Write("<br>");

      IExtendedControl c2 = new LableExtension2(new SimpleLabel());
      c2.Draw(Response);

      Response.Write("<br>");

      IExtendedControl c3 = new LableExtension2(new LableExtension1(new SimpleLabel()));
      c3.Draw(Response);
   }
}

Ausgabe des Beispielcodes:

I'm a simple Label
I'm a simple Label, decorated with LabelExtension1
I'm a simple Label, decorated with LabelExtension2
I'm a simple Label, decorated with LabelExtension1, decorated with LabelExtension2

Download der Anwendung:

DesignPatterns.zip (4.66 KB)

7/15/2006 3:10:33 PM (Mitteleuropäische Sommerzeit , UTC+02:00)  #    Disclaimer  |  Comments [4]  | 
 Wednesday, June 21, 2006

Sometimes it is necessary to change the user under whose account asp.net runs to execute a special method. This could be the case e.g. if you want to access an ADS with a local asp.net user and you get an error message "invalid username or password" (there is the possibility to pass a username and passwort, but that didn't work for me).

The usage of the class below is very simple:

...
Impersonation
imp = new Impersonation();
imp.ImpersonateValidUser(
"username", "domain", "password");
//execute your work here
imp.UndoImpersonation();
....




using
System;
using System.Security.Principal;
using System.Runtime.InteropServices;

namespace
Security
{

   public class Impersonation
   
{

      
public const int LOGON32_LOGON_INTERACTIVE = 2;
      
public const int LOGON32_PROVIDER_DEFAULT = 0;
      
WindowsImpersonationContext impersonationContext;

      [DllImport("advapi32.dll")]
      
public static extern int LogonUserA(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);

      public bool ImpersonateValidUser(String userName, String domain, String password)
      {
         
WindowsIdentity tempWindowsIdentity;
         
IntPtr token = IntPtr.Zero;
         
IntPtr tokenDuplicate = IntPtr.Zero;
         
         
if(RevertToSelf())
         {
            
if(LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE, 
               LOGON32_PROVIDER_DEFAULT,
ref token) != 0)
            {
               
if(DuplicateToken(token, 2, ref tokenDuplicate) != 0) 
               {
                  tempWindowsIdentity =
new WindowsIdentity(tokenDuplicate);
                  impersonationContext = tempWindowsIdentity.Impersonate();
                  
if (impersonationContext != null)
                  {
                     CloseHandle(token);
                     CloseHandle(tokenDuplicate);
                     
return true;
                  }
               }
            } 
         }

         if(token!= IntPtr.Zero) CloseHandle(token);
         
if(tokenDuplicate!=IntPtr.Zero) CloseHandle(tokenDuplicate);
         
return false;
      
}

      public void UndoImpersonation()
      {
         impersonationContext.Undo();
      }

   }
}

6/21/2006 8:07:46 AM (Mitteleuropäische Sommerzeit , UTC+02:00)  #    Disclaimer  |  Comments [1]  | 
 Wednesday, May 17, 2006
Anwendungsfall:
  • Es soll nur eine Instanz der Klasse existieren bzw. es soll nicht möglich sein, mehrere Instanzen der Klasse innerhalb eines Anwendungskontexts zu erzeugen.

Beispiele für die Anwendung:

  • Loadbalancer
  • ConnectionPools

Grafische Darstellung:

Beispielcode:

public class Singleton
{

   
private static Singleton instance;

   
private Singleton()
   {
   }

   public static Singleton GetInstance()
   {
      if (Singleton.instance == null)
      {
         Singleton.instance = new Singleton();
      }
      return Singleton.instance;
   }

}

5/17/2006 5:13:25 PM (Mitteleuropäische Sommerzeit , UTC+02:00)  #    Disclaimer  |  Comments [0]  | 

Problem:
You created a WebSite in Visual Studio 2005 and added a reference to another project or a .dll.
Now, if you want to remove this reference, you can't simply delete the .dll in the "Bin" folder of the WebSite. After a rebuild, the deleted .dll will be recreated from VS automatically.

Solution:
To remove the reference, open the Proptery Pages of the WebSite (right click on your WebSite in Solution Explorer and select "Property Pages"). The first time after a restart of VS, you will get the following "dialog":

Just try it once again, and it will work. Here you can remove your reference permanently.

5/17/2006 11:07:33 AM (Mitteleuropäische Sommerzeit , UTC+02:00)  #    Disclaimer  |  Comments [0]  | 
 Tuesday, May 16, 2006

Search for the file setup.sdb on your cd or dvd.

There, normally on the last line, you will find an entry with the headline "[Product Key]".

This is the case for e.g. Visual Studio Team Foundation Server 2005 or for Visual Studio Team Suite 2005.

5/16/2006 4:04:56 PM (Mitteleuropäische Sommerzeit , UTC+02:00)  #    Disclaimer  |  Comments [1]  |