Using system;
Using System.directoryServices;
Namespace systemframeworks.helper
{
///
/// Active directory auxiliary class. Package a series of active directory operations related methods.
///
Public Sealed Class Adhelper
{
///
/// domain name
///
Private static string domainname = "mydomain";
///
/// LDAP address
///
Private static string ldapdomain = "DC =
Mydomain
,
DC
= LOCAL ";
///
/// LDAP binding path
///
Private static string adpath = "ldap://brooocks.mydomain.local";
///
/// log in account
///
Private static string aduser = "administrator";
///
/// login password
///
Private static string adpassword = "password";
///
/// Play an example
///
Private static identityimpersonation impersonate = new IdentityimPersonation (aduser, adpassword, domainname);
///
/// User login verification result
///
Public Enum LoginResult
{
///
// Normal login
///
Login_user_ok = 0,
///
/// User does not exist
///
Login_user_doesnt_exist,
///
/// User account is disabled
///
Login_user_account_inactive,
///
/// user password is incorrect
///
Login_user_password_incorRect
}
///
// User Attribute Definition Sign
///
Public enum ads_user_flag_enum
{
///
/// Log in to the script flag. This flag is invalid if you read or write through the ADSI LDAP. If you pass through the ADSI WINNT, the logo is read-only.
///
ADS_UF_Script = 0x0001,
///
/// User account disable flag
///
ADS_UF_ACCOUNTDISABLE = 0x0002,
///
// main folder flag
///
ADS_UF_HOMEDIR_REQUIRED = 0x0008,
///
/// expired sign
///
ADS_UF_LOCKOUT = 0x0010,
///
/// User password is not necessary
///
ADS_UF_PASSWD_NOTREQD = 0x0020,
///
/// password cannot be changed
///
ADS_UF_PASSWD_CANT_CHANGE = 0x0040,
///
/// Use reversible encryption to save password
///
ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED = 0x0080,
///
// / Local account sign
///
ADS_UF_TEMP_DUPLICATE_ACCOUNT = 0x0100,
///
/// Normal user's default account type
///
ADS_UF_NORMAL_ACCOUNT = 0x0200,
///
/// Cross-domain trust account logo
///
ADS_UF_INTERDOMAIN_TRUST_ACCOUNT = 0x0800, ///
/// Workstation trust account logo
///
ADS_UF_WORKSTATION_TRUST_ACCOUNT = 0x1000,
///
// server trust account logo
///
ADS_UF_SERVER_TRUST_ACCOUNT = 0x2000,
///
/// password never expired
///
ADS_UF_DONT_EXPIRE_PASSWD = 0x10000,
///
/// MNS account logo
///
ADS_UF_MNS_LOGON_ACCOUNT = 0x20000,
///
/// Interactive login must use smart card
///
ADS_UF_SMARTCARD_REQUIRED = 0x40000,
///
/// When setting the flag, the service account (user or computer account) will be trusted by Kerberos.
///
ADS_UF_TRUSTED_FOR_DELEGATION = 0x80000,
///
/// When setting the flag, even if the service account is trusted by Kerberos, the sensitive account cannot be delegated.
///
ADS_UF_NOT_DELEGATED = 0x100000,
///
/// This account requires the DES encryption type
///
ADS_UF_USE_DES_KEY_ONLY = 0x200000,
///
// / Do not perform Kerberos pre-authentication
///
ADS_UF_DONT_REQUIRE_PREAUTH = 0x4000000,
///
/// User password expired sign
///
ADS_UF_PASSWORD_EXPIRED = 0x800000,
///
/// User account can be entrusted
///
ADS_UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION = 0x1000000
}
Public adhelper ()
{
//
}
#Region getDirectoryObject
///
/// Get the DirectoryEntry object instance, log in to the Administrator
///
///
Private static directoryentry getDirectoryObject ()
{
DirectoryEntry Entry = New DirectoryEntry (Adpath, ADUser, Adpassword, AuthenticationTypes.Secure);
Return Entry;
}
///
// / get the corresponding DirectoryEntry entity according to the specified username and password
///
///
///
///
Private Static DirectoryEntry GetDirectoryObject (String UserName, String Password)
{
DirectoryEntry Entry = New DirectoryEntry (Adpath, UserName, Password, AuthenticationTypes.none);
Return Entry;
}
///
/// i.e. / cn = users, dc = Creditsights, DC = cybelves, DC = COM
///
///
///
Private statoryEntry GetDirectoryObject (String DomainReference)
{
DirectoryEntry Entry = New DirectoryEntry (Adpath DomainReference, ADuser, Adpassword, AuthenticationTypes.Secure); Return Entry
}
///
/// Get DirectoryEntry created with username, password
///
///
///
///
///
Private Static DirectoryEntry GetDirectoryObject (String UserName, String Password)
{
DirectoryEntry Entry = New DirectoryEntry (Adpath DomainReference, UserName, Password, AuthenticationTypes.Secure);
Return Entry;
}
#ndregion
#Region getDirectoryEntry
///
/ / According to the user's public name
Object
///
/// user public name
///
If you find the user, return to the user.
Object; otherwise returning NULL
Public Static DirectoryEntry GetDirectoryEntry (String Commonname)
{
DirectoryEntry de = getDirectoryObject ();
DirectorySEARCHER DeSearch = New DirectorySearcher (DE);
Desearch.filter = "(& (ObjectCategory = Person) (CN =" CommonName ")";
Desearch.searchscope = searchscope.subtree;
Try
{
SearchResult results = desearch.findone ();
DE = New DirectoryEntry (Result.Path);
Return de;
}
Catch
{
Return NULL;
}
}
///
/ / Once the user is obtained according to the user's public name and password
Object.
///
/// user public name
/// user password
///
If you find the user, return to the user.
Object; otherwise returning NULL
Public Static DirectoryEntry GetDirectoryEntry (String Commonname, String Password)
{
DirectoryEntry de = getDirectoryObject (Commonname, Password);
DirectorySEARCHER DeSearch = New DirectorySearcher (DE);
Desearch.filter = "(& (ObjectCategory = Person) (CN =" CommonName ")";
Desearch.searchscope = searchscope.subtree;
Try
{
SearchResult results = desearch.findone ();
DE = New DirectoryEntry (Result.Path);
Return de;
}
Catch
{
Return NULL;
}
}
///
/ / / According to the user account number
Object
///
/// User account name
///
If you find the user, return to the user.
Object; otherwise returning NULL
Public Static DirectoryEntry GetDirectoryEntryByAccount (String Samaccountname)
{
DirectoryEntry de = getDirectoryObject ();
DirectorySEARCHER DeSearch = New DirectorySearcher (DE);
Desearch.filter = "(& (ObjectCategory = Person) (SamaccountName =" SamaccountName ")"
Desearch.searchscope = searchscope.subtree;
Try
{
SearchResult results = desearch.findone ();
DE = New DirectoryEntry (Result.Path);
Return de;
}
Catch
{
Return NULL;
}
}
///
/ / Once the user is obtained according to user account and password
Object
///
/// User account name
/// user password
///
If you find the user, return to the user.
Object; otherwise returning NULL
Public Static DirectoryEntry GetDirectoryEntryByAccount (String Samaccountname, String Password)
{
DirectoryEntry de = getDirectoryEntryByAccount (SamaccountName);
IF (de! = null)
{
String commonname = de.properties ["cn"] [0] .tostring ();
IF (COMMONNAME, PASSWORD)! = NULL)
Return getDirectoryEntry (Commonname, Password);
Else
Return NULL;
}
Else
{
Return NULL;
}
}
///
/ / According to the group name
Object
///
/// group name
///
Public Static DirectoryEntry GetDirectoryEntryOfGroup (String Groupname)
{
DirectoryEntry de = getDirectoryObject ();
DirectorySEARCHER DeSearch = New DirectorySearcher (DE);
Desearch.filter = "(& (ObjectClass = Group) (cn =" groupname ")";
Desearch.searchscope = searchscope.subtree;
Try
{
SearchResult results = desearch.findone ();
DE = New DirectoryEntry (Result.Path);
Return de;
}
Catch
{
Return NULL;
}
}
#ndregion
#Region getProperty
///
/// Get the designation
Specifies the value corresponding to the attribute name
///
///
/// attribute name
///
Attribute value
Public Static String GetProperty (DirectoryEntry de, String property)
{
IF (de.properties.contains (propertyname))
{
Return de.properties [propertyname] [0] .tostring ();
}
Else
{
Return string.empty;
}
}
///
/// Get the specified search results
Specify the value corresponding to the attribute name
///
///
/// attribute name
///
Attribute value
Public Static String GetProperty (SearchResult SearchResult, String PropertyName)
{
IF (SearchResult.properties.Contains (propertyname))
{
Return SearchResult.properties [PropertyName] [0] .tostring ();
}
Else
{
Return string.empty;
}
}
#ndregion
///
/// Settings
Attribute value
///
///
/// attribute name
/// attribute value
Public Static Void SetProperty (DirectoryEntry DE, String PropertyName, String PropertyValue)
{
IF (PropertyValue! = String.empty || PropertyValue! = "" || PropertyValue! = null)
{
IF (de.properties.contains (propertyname))
{
de.properties [PropertyName] [0] = PropertyValue;
}
Else
{
de.properties [PropertyName] .add (PropertyValue);
}
}
}
///
/// Create a new user
///
/// DN position. For example: OU = shared platform or cn = user
// / public name
/// account number
/// password
///
Public Static DirectoryEntry CreateNewUser (String Ldapdn, String Samaccountname, String Password)
{
DirectoryEntry entry = getdirectoryObject ();
DirectoryEntry SubenTry = entry.children.find (ldaPDN);
DirectoryEntry deUser = Subentry.children.Add ("CN =" CommonName, "User");
DEUSER.PROPERTIES ["SamaccountName"]. Value = SamaccountName
DEUSER.commitchanges ();
Adhelper.enableuser (Commonname);
Adhelper.SetPassword (CommonName, Password);
DEUSER.CLOSE ();
Return deuse;
}
///
/// Create a new user. Create by default under the Users unit.
///
// / public name
/// account number
/// password
///
Public Static DirectoryEntry CreateNewUser (String Samaccountname, String Password) {
Return CreateNewuser ("CN = Uses", CommonName, SamaccountName, Password;
}
///
/// Determine if the user of the specified public name exists
///
/// user public name
///
Return true if there; otherwise returning false
Public Static Bool IsuseRexists (String Common "
{
DirectoryEntry de = getDirectoryObject ();
DirectorySEARCHER DeSearch = New DirectorySearcher (DE);
Desearch.filter = "(& (ObjectCategory = Person) (cn =" commonname ")"; // LDAP query string
SearchResultCollection results = duence.findall ();
IF (results.count == 0)
Return False;
Else
Return True;
}
///
/// Determine if the user account is activated
///
/// User Account Properties Controller
///
Return true if the user account is activated; otherwise returns false
Public Static Bool IsaccountActive (int useractControl)
{
INT uSERACCOUNTCONTROL_DISABLED = Convert.Toint32 (ADS_USER_FLAG_ENUM.ADS_UF_ACCOUNTDISABLE);
Int flagXists = useeraccountControl & UseraccountControl_disabled;
IF (Flagexists> 0)
Return False;
Else
Return True;
}
///
/// Determine if the user and the password are sufficient to meet the authentication and then log in
///
/// user public name
/// password
///
Returns true if you can log in normally; otherwise return false
Public Static loginResult login (String Commonname, String Password)
{
DirectoryEntry de = getDirectoryEntry (Commonname);
IF (de! = null)
{
/ / The account activation attribute must be judged before determining the user password; otherwise an exception will appear.
INT useraccountControl = Convert.Toint32 (de.properties ["UseraccountControl"] [0]);
de.close ();
IF (! isaccountactive (useeraccountControl))
Return LoginResult.login_user_account_inactive;
IF (COMMONNAME, PASSWORD)! = NULL)
Return LoginResult.login_user_ok;
Else
Return loginResult.login_user_password_incorRect;
Else
{
Return LoginResult.login_user_doesnt_exist;
}
}
///
/// Determine if the user account and the password are sufficient to meet the authentication and log in
///
/// user account
/// password
///
Returns true if you can log in normally; otherwise return false
Public Static LoginResult LoginByAccount (String Samaccountname, String Password)
{
DirectoryEntry de = getDirectoryEntryByAccount (SamaccountName);
IF (de! = null)
{
/ / The account activation attribute must be judged before determining the user password; otherwise an exception will appear.
INT useraccountControl = Convert.Toint32 (de.properties ["UseraccountControl"] [0]);
de.close ();
IF (! isaccountactive (useeraccountControl))
Return LoginResult.login_user_account_inactive;
GetDirectoryEntrybyAccount (SamaccountName, Password)! = null)
Return LoginResult.login_user_ok;
Else
Return loginResult.login_user_password_incorRect;
}
Else
{
Return LoginResult.login_user_doesnt_exist;
}
}
///
/// Set the user password, the administrator can modify the password of the specified user.
///
/// user public name
/// user new password
Public Static Void SetPassword (String Commonname, String NewPassword)
{
DirectoryEntry de = getDirectoryEntry (Commonname);
// Simulate super administrators to achieve permission to modify user password
Impersonate.beginimpersonate ();
de.invoke ("setPassword", new object [] {newpassword};
Impersonate.stopimpersonate ();
de.close ();
}
///
/// Set the account password, the administrator can modify the password of the specified account.
///
/// user account
/// user new password
Public Static Void SetPasswordByAccount (String Samaccountname, String NewPassword)
{
DirectoryEntry de = getDirectoryEntryByAccount (SamaccountName);
// Simulate super administrators to achieve permission to modify user password
Identityimpersonation Impersonate = New IdentityimPersonation (ADUser, Adpassword, DomainName);
Impersonate.beginimpersonate ();
de.invoke ("setPassword", new object [] {newpassword};
Impersonate.stopimpersonate ();
de.close ();
}
///
// / Modify user password
///
/// user public name
/// old password
/// new password
Public Static Void ChangeUserpassword (String Commonname, String Newpassword)
{
// to-do: Need to solve password policy issues
DirectoryEntry Ouser = getDirectoryEntry (Commonname);
OUSER.INVOKE ("ChangePassword", New Object [] {oldpassword, newpassword});
OUSER.CLOSE ();
}
///
// Enable users specified public name
///
/// user public name
Public static void enableuser (String Commonname)
{
Enableuser (COMMONNAME);
}
///
// Enable specified
User
///
///
Public Static Void Enableuser (DirectoryEntry DE)
{
Impersonate.beginimpersonate ();
De.properties ["UseraccountControl"] [0] = adhelper.ads_user_flag_enum.ads_uf_normal_account | adhelper.ads_user_flag_enum.ads_uf_dont_expire_passwd;
de.commitchanges ();
Impersonate.stopimpersonate ();
de.close ();
}
///
// / Users who disable the designated public name
///
/// user public name
Public static void disableuser (String Commonname)
{
Disableuser (COMMONNAME));
}
///
// / Disabled designation
User
///
///
Public Static Void Disableuser (DirectoryEntry DE)
{
Impersonate.beginimpersonate ();
de.Properties [ "userAccountControl"] [0] = ADHelper.ADS_USER_FLAG_ENUM.ADS_UF_NORMAL_ACCOUNT | ADHelper.ADS_USER_FLAG_ENUM.ADS_UF_DONT_EXPIRE_PASSWD | ADHelper.ADS_USER_FLAG_ENUM.ADS_UF_ACCOUNTDISABLE;
de.commitchanges ();
Impersonate.stopimpersonate ();
de.close ();
}
///
/// Add the specified user to the specified group. The group and user under Users.
///
/// user public name
/// group name
Public Static Void Addusertogroup (String UserCommonname, String Groupname)
{
DirectoryEntry OGroup = getDirectoryEnTryOfGroup (groupname);
DirectoryEntry Ouser = getDirectoryEntry (UserCommonname);
Impersonate.beginimpersonate ();
Ogroup.properties ["Member"]. add (OUSER.PROPERTIES ["DISTINGUISHEDNAME"]. Value); OGroup.commitchanges ();
Impersonate.stopimpersonate ();
Ogroup.close ();
OUSER.CLOSE ();
}
///
/// Remove the user from the specified group. The group and user under Users.
///
/// user public name
/// group name
Public Static Void RemoveUserFromGroup (String UserCommonname, String Groupname)
{
DirectoryEntry OGroup = getDirectoryEnTryOfGroup (groupname);
DirectoryEntry Ouser = getDirectoryEntry (UserCommonname);
Impersonate.beginimpersonate ();
Ogroup.properties ["MEMBER"]. Remove (OUSER.PROPERTIES ["DISTINGUISHEDNAME"]. Value);
Ogroup.commitchanges ();
Impersonate.stopimpersonate ();
Ogroup.close ();
OUSER.CLOSE ();
}
}
///
/// User simulates the role class. Implement the user role simulation within the block.
///
Public Class IdentityImPersonation
{
[DLLIMPORT ("Advapi32.dll", SetLastError = true)]
Public Static Extern Bool Logonuser (String Lpszusername, String Lpszdomain, String Lpszpassword, int dwlogontype, int dwlonprovider, ref INTPTPTR phoken);
[DLLIMPORT ("Advapi32.dll", Charset = charset.auto, setLastError = true)]
Public Extern Static Bool DuplicateToken (INT Security_impersonation_level, ref INTPTR DUPLICATETOLENDE);
[DLLIMPORT ("kernel32.dll", charset = charSet.Auto)]
Public Extern Static Bool CloseHandle (INTPTR HANDLE);
// User name, password, domain (machine name) to be simulated
Private string _simperusername;
Private string _simperpassword;
Private string _simperdomain
// Record the simulation context
Private windowsimpersonationContext_impercontext;
Private INTPTR _ADMINTOKEN;
Private INTPTR _DUPETOKEN
/ / Whether it has stopped simulation
Private boolean _bclosed;
///
/// Constructor
///
/// user name of the user to simulate
/// The password of the user to simulate
/// The domain where the user wants to simulate
Public IdentityimPersonation (String ImpersonationUsername, String ImpersonationDomain) {
_simperusername = impersonation ionUsername;
_simperpassword = impersonationpassword;
_simperdomain = impersonationdomain;
_admintoken = INTPTR.ZERO;
_dupetoken = intptr.zero;
_bclosed = true;
}
///
/// destructor
///
~ IdentityimPersonation ()
{
IF (! _ bclosed)
{
Stopimpersonate ();
}
}
///
/// Start identity role simulation.
///
///
Public Boolean Beginimpersonate ()
{
Boolean blogined = logonuser (_SIMPERUSERNAME, _SIMPERDOMAIN, _SIMPERPASSWORD, 2, 0, REF _ADMINTOKEN);
IF (! blogined)
{
Return False;
}
Boolean bduped = duplicatetoken (_ADMintoken, 2, ref _dupetoken);
IF (! bduped)
{
Return False;
}
Windowsidentity Fakeid = New WindowsIdentity (_DuPetoken);
_impercontext = fakeid.impersonate ();
_BClosed = false;
Return True;
}
///
/// Stop the identity role simulation.
///
Public void stopimpersonate ()
{
_impercontext.undo ();
CloseHandle (_DuPetoken);
CloseHandle (_ADMINTOKEN);
_bclosed = true;
}
}
Posted @
2004-09-16 09:44 Josson Read (21) |
Comments (0) |
edit
Collect
September 9, 2004 #
Modify the trust level in the SPS site
Open the web.config file in the root of the SPS virtual site, find the following line:
Modify it to:
Fig. 4: Web Part Class Attributes Het TOEVOEGEN VAN Extra Web Part Properties Werkt Hetzelfde Als Het Toevoegen Van Properties Aan 'Normale' C # Classes. We Passen de StandaardWaarde Van de Property Text Aan. Met Het Attribute Browsable GEVEN WE AAN DAT De Property Via Het Web Interface in de Portal AangePast Kan Worden. De Category waarin deze eigenschap in het task pane getoond zal worden is "Miscellaneous". Wanneer je meerdere eigenschappen aan een Web Part hebt toegevoegd, kun je ervoor kiezen een eigen categorie toe te voegen door hier een andere naam in te vullen. De Web Part Storage eigenschap bepaalt hoe de Web Part eigenschappen worden opgeslagen in de SharePoint database. De standaard waarde Personal betekent dat de waarde voor elke gebruiker wordt opgeslagen. Als je de waarde op Shared zet, wordt de property voor alle gebruikers opgeslagen. Wanneer je de Storage eigenschap op None zet, wordt de standaard waarde gebruikt en wordt de waarde van de eigenschap niet in de SharePoint database opgeslagen, maar wordt de standaard waarde in het Web Part getoond.Fig 5:. Aangepaste code Web Part property "Text" Fig. 6: Web Part Properties Aanpassen in de Portal Web Parts zijn bijzondere .NET Custom Controls. Dat betekent dat er geen grafische interface is waarmee je je Web Part kunt aanpassen. (Je kunt geen knoppen op je Web Part slepen.) In plaats daarvan bouw je je Web Part op in de RenderWeb Part Method, Die Je Kunt Vergelijken Met De Render Method Van Een Custom Control. Standaard staat in de RenderWeb Part method code die ervoor zorgt dat de Text property van het Web Part getoond wordt. Deze code vervangen we door code om de naam van de CurrentUser te tonen. Hiervoor gebruiken we het Context object. Fig. 7: AangePaste Code Web Part Method "Renderwebpart" TIP: Het Context Object Kun Je Gebruiken Om Informatie OP TE VRAGEN OVER DE CONTEXT VAN HET Web Part: De Current User En de Site Waarin Het Web Part IS GePlatSt. Voorbeeld: USING Microsoft.SharePoint.WebControls SPWEB myWeb = spControl.getContextWeb (Context); String username = myWeb.currentuser.loginname; MyWeb Is de SharePoint Site Waarop Het Web Part IS GEPLAATST. WebPartUser.dwp Bij elk Web Part hoort een .dwp bestand, waarin de Web Part eigenschappen staan ingesteld:.. Titel, Description, Assembly en TypeName De Title en Description worden getoond wanneer gebruikers het Web Part in de portal plaatsen De Description verschijnt als tooltip.Het is belangrijk dat de Assembly en TypeName correct zijn ingevuld, omdat deze aangeven welke class de functionaliteit van het Web Part bevat. We veranderen de bestandsnaam in WebPartUser.dwp, en de TypeName in WebPartUser, zodat deze overeenkomt met de naam van de Web Part class. Web Part eigenschappen kunnen ook in de Web Part definitie file worden vastgelegd Wanneer we ons Web Part bijvoorbeeld standaard 20 pixels hoog willen maken voegen we de volgende tag toe:. Een Web Part Zonder Frame Tonen Kan Als Volgt: Fig. 8: AangePaste Code Web Part Method "Renderwebpart" TIP: Wanneer je een overzicht wilt hebben van de Web Part eigenschappen die je via de Web Part definitie kunt vastleggen, kun je de pagina waarop het Web Part is geplaatst in Microsoft FrontPage 2003 openen. Elk Web Part wordt in de broncode van de pagina als XML getoond . TIP: De foutmelding "A Web Part or Web Form Control on this Web Part Page can not be displayed or imported, because it is not registered on this site as safe" treedt op wanneer het dwp bestand onjuist is aangepast. De Typename moet kloppen! Manifest.xml In Het Manifest Staat ALLE INFORMATIE DIE NODIG IS OM HET Web Part Op de Server TE Installeren. We Passen de Naam Van Het DWP File Aan. Fig. 9: Web Part Manifest Wanneer je Web Part gebruik maakt van bestanden die opgeleverd moeten worden met het Web Part, zet je in het manifest ook verwijzingen naar deze bestanden. Deze verwijzingen staan in de ClassResources tag. Wij verwijderen de ClassResources tag, omdat we voor ons Web Part geen andere Bestanden Nodig Hebben.tip: In Het Manifest Geef Je Ook Aan Welke Resources (Bestanden) Met Het Web Part OpGeleverd MoeTen Worden. Standaard Staat Deze XML Tag Niet UITGECOMMATARIEERD. Wanneer Je de Foutmelding "Can't Find this file specified in the file manifest.xml" Krijgt, Moet Je de Lege ClassResources Tag Uit Het Manifest Verwijderen. AskEMBLY INFORMATION Voordat de Web Part code op de server kan worden uitgevoerd, moet het Web Part als safe control geregistreerd zijn op de server. Hiervoor moeten we het voorzien van een strong name. Met de Strong Name tool (sn.exe) maken we een keyfile aan DIE WE AAN HET Project Toevoegen. de ENIGE AANPASSING DIE WE HOEVEN TE DOEN AAN DE Assembly Information Is Het Verwijzen Naar de KeyFile. Bijvoorbeeld: [Assembly: askEMBLYKEYFILE ("..//..// sdgn.snk")] Web PART OPLEVEREN OP DE Server Web Parts Worden Deployed in Web Part Packs: Cab Files Die Je Met Behull Van Een Setup Project Kunt Maken. Deze Web Part Packs Kunnen Op de SharePoint Server Worden Geregistreerd Met de Tool Stsadm.exe. Om het Web Part op te leveren voegen we eerst een Setup project toe aan de Web Part Solution Aan deze CAB file voegen we toe:.. De primary output van het Web Part project, het manifest en de Web Part definitie file (Wanneer je in DE ClassResources Tag Van Het Manifest Bestandsnamen Hebt Ingevuld, Moet Je Deze Ook Aan de Cab File Toevoegen.) Fig. 10: Setup project Met de tool Stsadm.exe registreren we de CAB file op de server. Wanneer je gebruik maakt deze tool wordt het Web Part automatisch aan de SafeControls verzameling toegevoegd in web.config. Om alle code in het webpart uit te kunnen voeren, wijzigen we het trust-level in web.config Het trus-tlevel dat nodig is voor het uitlezen van de ingelogde user is WSS_Medium ( Let op:. In de productieomgeving zal het niet wenselijk zijn om het trust-level te verruimen Dan zal gebruik gemaakt worden van "Custom trust levels", en wordt precies vastgelegd welke acties Web Parts op de server uit mogen voeren. We kunnen het Web Part nu registreren met stsadm De tool stsadm staat in de folder Wanneer Een Web Part GegeGistreerd IS, KAN Het NA Wijzigingen Met de Force Parameter Opnieuw Geregistreerd Worden. Met de Operation Deletewppack Kunnen Web Parts Van de Server Verwijderd Worden. Fig. 11: Web part deployment m.b.v. stsadm Fig. 12: Web Part van de Server Verwijderen Conclusie IN DIT Artikel Hebben We Een Web Part Ontwikkeld Met Behull Van Een Web Part Template. We hebben de eigenschappen van dit Web Part aangepast in code en met behulp van het Web Part definition bestand. We hebben code toegevoegd aan de RenderWebPart method, en het Web Part op de server geregistreerd met de tool stsadm. In de volgende artikelen over Web Part development zullen we ons Web Part project uitbreiden met nieuwe Web Parts met meer functionaliteit. Zoals Web Parts met controls en connected Web Parts (Web Parts die samenwerken met andere Web Parts op de pagina) .posted @ 2004-09-09 14:10 Josson Read (13) | Comments (0) | edit Collect SharePoint related links SharePoint Home: http://www.microsoft.com/sharepoint/sharePoint Portal Server Home: http://www.microsoft.com/office/sharepoint/prodinfo/default.mspx SharePoint Portal Server and SharePoint Service What is the difference: http: //www.microsoft.com/sharepoint/evaluationoverview.aspSharePoint Development Center: http: //msdn.microsoft.com/library/default.asp url = / nhp / Default? .asp contentid = 28001891SharePoint Service 2003 (2.0) Download:? http: //www.microsoft.com/downloads/details.aspx FamilyID = e084d5cb-1161-46f2-a363-8e0c2250d990 & DisplayLang = enSharePoint Service 2003 SDK Download:? http: / /www.microsoft.com/downloads/details.aspx?FamilyID=1c64af62-c2e9-4ca3-a2a0-7d4319980011&DisplayLang=enSharePoint Portal Server 2003 Eval Edittion: http: //www.microsoft.com/downloads/details.aspx FamilyID =? 16006564-4575-4463-920d-c920b4aeae64 & DisplayLang = enSharePoint Portal Server 2003 Administrator's Guide: http: //www.microsoft.com/downloads/details.aspx FamilyID = 16006564-4575-4463-920d-c920b4aeae64 & DisplayLang = enSharePoint University:? http: //www.sharepointu.com/ Previous SharePoint Services called SharePoint Team Service, the new version called Team Service 2.0, then renamed SharePoint Service 2003, then integrate the core service into Windows Server 2003, it is called Windows SharePoint ServiceHttp. : //blog.9cbs.net/kiclee/archive/2004/07/28/sharepoint_hotlink.aspx http://blog.joycode.com/kaneboy/category/791.aspxhttp://communities.microsoft.com/newsgroups/default.asp?ICP=chinacommunity&sLCID=cnwww.sharepointserver.comhttp://msd2d.com/default_section. Aspx? section = sharepointhttp://www.spsfaq.com/! http://www.sharepointcode.com/! http://ipattern.com/simpleblog/permlink.aspx?nTryid=38 Http://weblogs.asp.net/soever/category/1593.aspxhttp://weblogs.asp.net/mnissen/category/3130.aspxhtp://weblogs.asp.net/wkriebel/category/4089.aspxhttp: //weblogs.asp.net/jan/category/2443.aspxhttp://blogs.sqlxml.org/bryantlikes/category/18.aspxhttp://jj4.bloggedup.com/mt/http://www.skillat. COM / Blog / Posted @ 2004-09-09 14:04 Josson Read (17) | Comments (0) | edit Collect Increase system users in AD. // Add user string Dom = "ldap: //inTDomain.com/cn=users, diRectoryServices.directoryEntry", ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, DirectoryEntries myEntries = entry1.Children; DirectoryEntry myDirectoryEntry = myEntries.Add ( "CN = myuser", "user");. MyDirectoryEntry.Properties [ "givenname"] Value = "test";. MyDirectoryEntry.Properties [ "sn"] Value = "htestsn";. myDirectoryEntry.Properties [ "displayname"] Value = "testdisplayname";. myDirectoryEntry.Properties [ "mail"] Value = "testmail"; myDirectoryEntry.CommitChanges (); // set password .myDirectoryEntry.Invoke ( "SetPassword", newpassword); Posted @ 2004-09-09 14:02 Josson Read (11) | Comments (0) | edit Collect ActiveDirectory binding domain (Transfer) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/iadsuser.aspto bind to a domain user through a winnt provider, use the domain name as Part of the adspath, as shown in The Following Code EXAMPLE. GetObject ("Winnt: // Mydomain / Jeffsmith, User") SIMILARLY, USE The Computer Name as part of the adspath to bind to a local user. GetObject ("Winnt: // MyComputer / Jeffsmith, User") In Active Directory, domain users reside in the directory The following code example shows how to bind to a domain user through an LDAP provider.GetObject ( "LDAP:. // CN = Jeff Smith, OU = Sales, DC = Fabrikam, DC = COM ") However, local accounts reside in the local SAM database and the LDAP provider does not communicate with the local database Thus, to bind to a local user, you must go through a WinNT provider as described in the second code example.example:. // Binding domain, modify user password .direcotryentry entry = new DirectoryEntry ("Winnt: // devtest / josson", "josson", "pass"); // LDAP bind // new DirectoryEntry ("ldap: // devteest / Cn = jin, cn = users, dc = devtest, dc = com "," josson "," pass "); entry.invork (" ChangePassword ", new object [] {oldpassword, newpassword}); Posted @ 2004-09-09 13:57 Josson Read (12) | Comments (0) | edit Collect June 22, 2004 # Workflow related collection. Workflow is partially or as a whole, which is manifested as a participant to take action on files, information, or tasks, and deliver them between participants. Simply put, workflow is a series of mutually connected, automated business activities or tasks. http://www.delfan.com/workflow/ Posted @ 2004-06-22 11:20 Josson Read (73) | Comments (0) | edit Collect June 18, 2004 # Grip http://community.9cbs.net/expert/topic/3102/3102187.xml?temp =.8055536 Using system; Using system.drawing; Using system.collections; Using system.componentmodel; Using system.windows.forms; Using system.data; Using system.drawing.image; Using system.io; // Import the namespace used in the program Public Class Capture: Form { Private system.componentmodel.Container Components = NULL; Private icon MNettrayicon = New Icon ("TRAY.ICO"); Private bitmap myimage = null; Private notifyicon trayicon; Private contextmenu notifyiconmnu; Public capture () { // Initialize the components used in the form InitializationComponent (); } Protected Override Void Onactivated (Eventargs E) { THIS.HIDE (); } [System.Runtime.InteropServices.dllimportattribute ("gdi32.dll")]]]] Private static extern bool bitblt INTPTR HDCDEST, / / Target device handle INT NXDEST, / / X coordinate in the upper left corner of the target object INT NYDEST, / / X coordinate in the upper left corner of the target object INT NWIDTH, / / The width of the rectangle of the target object INT NHEIGHT, / / The length of the rectangle of the target object INTPTR HDCSRC, // Source Equipment Handle INT NXSRC, // / 坐 坐 坐 in the upper left corner of the source INT NYSRC, // 坐 坐 坐 坐 坐 坐 SYSTEM.INT32 DWROP / / Raster Operation Value ); [System.Runtime.InteropServices.dllimportattribute ("gdi32.dll")]]]] Private static extern INTPTR CREATEDC ( String lpszdriver, // Drive name String lpszdevice, // device name String lpszoutput, // is useless, you can set "NULL" INTPTR LPINITDATA / / Arbitrary Printer Data ); Public void Capture (Object Sender, System.EventArgs E) { THIS.Visible = FALSE; INTPTR DC1 = CREATEDC ("Display", NULL, NULL, (INTPTR) NULL); // Create a display of the DC Graphics g1 = graphics.fromhdc (dc1); // Create a new Graphics object by a handle of a specified device MyImage = new bitmap (Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.bounds.Height, G1); / / Create a Bitmap object with the same size according to the screen size Graphics g2 = graphics.fromimage (MyImage); // Get the handle of the screen INTPTR DC3 = G1.GETHDC (); // Get the handle of a bitmap INTPTR DC2 = G2.GETHDC (); // capture the current screen into the bitmap object Bitblt (DC2, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.primaryScreen.Bounds.Height, DC3, 0, 0, 13369376); / / Copy the current screen into the bit map G1.ReleaseHDC (DC3); // Release the screen handle g2.releaseHDC (DC2); // Release bitmap MyImage.save ("c: //myjpeg.jpg", imageformat.jpeg; Messagebox.show ("has already saved the current screen to the c: //myjpeg.jpg file!"); THIS.Visible = True; } Public Void EXITSELECT (Object Sender, System.EventArgs E) { // Hide icon in the tray program TRAYICON.Visible = false; // Turning system THIS.CLOSE (); } / / Clear the resources used in the program / * public override void dispose () { Base.dispose (); IF (Components! = NULL) Components.dispose (); } * / Private vidinitiRizeComponent () { / / Set the various properties of the tray program Trayicon = new notifyicon (); Trayicon.icon = mnettrayicon; TRAYICON.TEXT = "Do Screen Capture Program with C #"; TRAYICON.Visible = TRUE; / / Define a MenuItem array and assign this array to the ContextMenu object. Menuitem [] mnuitms = new menuItem [3]; Mnuitms [0] = new menuitem (); Mnuitms [0] .Text = "captures the current screen!" Mnuitms [0] .click = new system.eventhandler (this.capture); Mnuitms [1] = New Menuitem ("-"); Mnuitms [2] = new menuItem (); Mnuitms [2] .Text = "Exit System"; Mnuitms [2] .click = new system.EventHandler (this.exitslect); Mnuitms [2] .defaultItem = true; Notifyiconmnu = New ContextMenu (MNUITMS); Trayicon.ContextMenu = Notifyiconmnu; / / Add a set CONTEXTMENU object for the tray program THIS.SUSPENDLAYOUT (); THIS.AUTOSCALEBASESIZE = New System.drawing.size (5, 13); this.clientsize = new system.drawing.size (320, 56); THIS.CONTROLBOX = FALSE; THIS.MAXIMIZEBOX = FALSE; THIS.MINIMIZEBOX = FALSE; This.WindowsTate = system.windows.forms.formwindowstate.minimized; THIS.NAME = "Capture"; THIS.SHOWINTASKBAR = FALSE; THIS.TEXT = "Use C # to do the Screen Capture program!"; This.ResumeLayout (false); } Static void main () { Application.run (New Capture ()); } }