Cascade Skyline - with Microsoft Logo and Project Support header - author Brian Smith

  • Brian Smith's Microsoft Project Support Blog

    Sorry – another non-Project post – but take a look at Popfly Game Creator!

    • 0 Comments

    Going Live in Alpha today is the new Game Creator stuff on Popfly.  Seriously cool!   There is a Video demo up at Soapbox too.

    More information follows…

    The Popfly family just got a little bigger

    Popfly Game Creator | May 2nd 2008 | 12:01PM | 7lbs, 4oz | 20 inches | Proud Parents- The Popfly Team

    Starting today, game creation is now officially accessible to everyone.  You don’t have to be a physics major or hard-core coder to create your own personalized game using the Popfly Game Creator.  In fact, you can create your first game in three easy steps through Popfly’s intuitive interface.

    1. Select your actors:  Choose from nearly 400 pre-built actors in categories like people, vehicles, power-ups, and more.  Can’t find what you’re looking for? Import and create your own.

    clip_image001

    2. Set the scene:  Pick a background, select some sounds, and position your actors through a visual designer.

    clip_image002

    3. Bring your game to life:  This is where the magic happens.  Using Popfly, you can specify behaviors on your actors and scenes that define how they should interact. Use Popfly’s intuitive user interface to define events, set properties, and specify actions without writing a single line of code!  If you want more control, define a custom behavior in JavaScript.

    clip_image003

    Creating Games has never been easier.

    To learn more and build your first game head over to www.popfly.com

  • Brian Smith's Microsoft Project Support Blog

    Project Server 2003 and Multilingual User Interface Packs

    • 1 Comments

    A rare Project Server 2003 posting from me to clarify some issue we see with customers applying the MUIs to Project Server 2003.

    Firstly if you are interested in using MUIs then 2007 language packs address some of the issues that 2003 suffers from.  2007 is unicode and you can mix and match languages without the restrictions in 2003.  But if you must still use 2003…

    Unlike the language packs for Project Server 2007 the MUI itself does not contain a Project Workspace template for the MUI language.  In KB articles we do say how this can be added by running WSSWIZ for the appropriate language – but then don’t give any details of where you might find this!  Add to this the fact that for any language the file has the same name it is not surprising customers get confused!

    The WSSWIZ you need to run can be found on the native language CD of Project Server 2003 for the language you want to add.  The next problem is therefore that you are unlikely to have this CD.  For instance, if you are loading French MUI on the US English version you will have the US CD and the downloaded MUI – but you will not have the French CD!  I will let someone else jump in if the following appears to be a licensing issue – but from reading the public material my take on this is we intend people with MUI to also be able to use foreign language workspaces – but didn’t think through distribution of the WSSWIZ.  If you have an account manager then I would liaise with them to obtain the right media.  You could also find this on MSDN media – and I am not talking about using the full install – but just using the WSSWIZ stuff from the \support\wsswiz directory.  You may also find this on your volume licensing media – but I have seen one issue with the French CD where onet.xml file was empty – so if you use MSVL and don’t appear to get the French template then check if you are hitting this issue.

    On a very related issue another file used during MUI installation is INSDEFLP.sql which adds the language strings to the database.  Since SP2a we do actually install this file correctly – but you still need to be sure you are running the version for the right language.

    From  http://support.microsoft.com/kb/906429/ where this issue is fixed… 

    You cannot update databases when you install Microsoft Multilingual User Interface Pack (MUI) on Project Server 2003
    When you install Microsoft Multilingual User Interface Pack (MUI) on Project Server 2003, you receive a warning message that states that only the default database will be updated if the server contains more than one database. The message also states that the Insdeflp.sql file will have to be run against the other databases. However, the message does not indicate the location of the Insdeflp.sql file. The Insdeflp.sql file is never installed to the system. Therefore, you cannot run the script against the other Project Server databases.

    You need to look in the directory with the appropriate LCID – such as C:\Program Files\Microsoft Office Project Server 2003\SCRIPTS.SQL\1036 for French.  Also remember that MUI has service packs to match the base product service packs.

    Technorati Tags: ,
  • Brian Smith's Microsoft Project Support Blog

    Which master pages can you edit in Project Server 2007?

    • 15 Comments

    A recent support incident showed that some of our documentation didn’t make it clear just what you can and can’t do with master pages.  There are two different types of sites in Project – PWA (the Project Web Access sites) and PWS (the project workspace sites).  For the PWA sites you are limited to making use of the default.master we already supply to give any extra pages the same look and feel, but you are not able to edit these default.master pages.  We also block SharePoint Designer from opening these sites – so you cannot use this tool against a PWA site.  You can however use SharePoint Designer against the PWA workspace sites – and edit the default.master.

    The reason for this difference is that it would be easy to break our application by editing our pages – and this would not make life good for a support engineer (and indeed for the customers who manage to break things!).  Also remember that even though the workspaces can be modified you shouldn’t add extra instances lists of the specific project type lists of issues, risks, dependencies and documents.  Details from these default lists feed through to the reporting database – if there are duplicates then this will break the workspace reporting feature.

    This topic is covered at http://msdn.microsoft.com/en-us/library/ms504195.aspx and this highlights another great way you can add to the sum of human knowledge on MSDN.  BruceVB added some community content based on his experience – and our own Jim Corbin has added a further comment.  Although I wouldn’t necessarily agree that our original document is incorrect – it is certainly not complete in telling you what you can and cannot do.  But even being able to use our default.master on new pages does make it easier to build custom Project Web Access solutions – even if you cannot edit the default.master.

    If you do try and update the PWA default.master through Site Actions, Site Settings then you may see the error message "The enablesessionstate attribute on the page directive is not allowed in this page." 

    You would need to reset to the site definition to get the site working again. 

    Please do use the community content features on MSDN – it certainly does help us to understand how we can improve our content – and thanks again BruceVB for bringing this particular problem to our attention.

  • Brian Smith's Microsoft Project Support Blog

    100 Posts Today!

    • 1 Comments

    According to my blog dashboard this is my 100th post!  So to celebrate I thought I would be totally self-indulgent (so nothing new there) and ignore Project and talk about something else.  It has been fun keeping the blog going and also great to have communication with so many of you – either through the blog (600+ comments, and rising) or on support cases or at the Project conference.  Keep the comments coming – and the answers too, as I will sometimes post questions I don’t have the answers for.

    If you didn’t already know I am from the UK, but moved to the Seattle area about 5 1/2 years ago and live on the Snoqualmie Valley.  My journey to and from the office gives me the chance to see some of the great beauty that the Pacific North West has to offer – and even this time of year when it has been known to rain we still get great mountain views at some point on most days.  One of my other interests is photography – and in fact my first career was in the research labs formulating developers and fixers when photography was still “wet”.  I knew that wouldn’t last – so on to computers and digital!  I was recently very fortunate to visit Hawaii for the first time – so took lots of photos – but it is testament to the beauty of the local countryside that for my desktop wallpaper I have chosen recent local pictures I have taken over the Hawaiian paradise.

    Mountains_24

    This first one is looking East from my house just before sunset.  The second one was last Friday evening – when a tree that will regularly have Bald Eagles perched in it had 7!  So back out with my camera to get some pictures – including this one of an immature bald eagle in flight.

    Eagles_11Crop

    I know we have other keen and very capable photographers in the Project community and Jack Dahlgren has posted some spectacular ones too http://zo-d.com/blog/archives/architecture/bay-bridge-at-sunrise.html.

    So posting 101 will be back on topic, but I might just post the occasional photo too…

  • Brian Smith's Microsoft Project Support Blog

    Impersonation Within a Project Server 2007 Server-Side Event Handler

    • 34 Comments

    One topic that our customers and partners seem to be having a hard time with is impersonation.  One reason is that the term we are using – impersonation – may already mean something to developers, and so the specific steps required to get impersonation working for Project Server 2007 and the PSI aren’t taken into consideration.  The SDK covers this in a couple of topics, but to show a couple more examples I’ve prepared a couple of event handlers that show what happens when you use and don’t use impersonation.

    What does impersonation achieve with event handlers?  It allows a an event handler to take action as a particular user – and this is useful for a few different reasons.

    1.  Whatever transaction that is carried out will be running as a chosen user – so it will look as though this user made any changes – and this will be reflected in any user accounts associated with the transaction.

    2.  The account running the event service (the SSP administrator) does not need to be a user in PWA and/or have any specific permissions.

    3.  For certain web services, particularly statusing, the call returns data based on the user making the request – so you need to pretend to be the user in question – rather than the SSP Admin.

    If you don’t impersonate and the SSP Admin is not a user in PWA you will get errors like The request failed with HTTP status 401: Unauthorized.  If this exception is not handled it will also mean the event handler crashes and if it is a “pre” event it will be canceled. Depending on where the event comes from the user may or may not get any notification that the cancellation occurred – so you need to code for this .  If they are a user, then they will need the right permissions for whichever web service they are calling – and if they call a statusing web service such as ReadStatus then the result will be the tasks for the SSP Admin – and not for the user who triggered the request.

    If you do impersonate then you don’t need to be a user in PWA, and a request to ReadStatus gets the tasks for the user who triggered the request.

    My code sample below shows the same code both with and without impersonation and catches the timesheet OnCreated event, and also the statusing  OnStatusUpdate.  The event handlers don’t do anything useful – just write to the event log both some data from the event payload and also make a request to a web service and write some details of the response – just to illustrate the differences seen when impersonating.

    As usual, my samples don’t include the level of exception handling you should include – and also include some hard coded values that you may wish to either use in application settings or to resolve at run-time using reflection.  Remember that with event handlers, and particularly the “pre” events, you want your code to be very light weight.  Also remember that in “pre” events that although you have access to more of the payload than post events you cannot modify it.

    For my sample responding the the timesheet OnCreated  event that does not use impersonation then if the SSP Admin is not a user we get the expected 401 error – whoever creates a timesheet, because the call to the ReadTimesheet fails.  If the SSP Admin is a user but is just a team member then the call to ReadTimesheet will work ONLY when the SSP Admin creates a timesheet – but will fail with a GeneralSecurityAccessDenied error from the event handler – as the SSP Admin cannot read anyone else’s timesheet.  If they are an administrator (or explicitly have the View Resource Timesheet global permission)  then they can successfully call the ReadTimesheet and the event handler will work.  If the same is done using impersonation then it will work regardless of the SSP Admin permissions – and they do not even need to be a user in Project Server.

    For the sample responding to the statusing OnStatusUpdate event that does not use impersonation we see slightly different behavior.  We still see failure if the SSP is not a user (401), but if they are a user then the call to ReadStatus will work – but does not return the number of tasks for the user who triggered the event – but always the number of tasks for the SSP Admin (so only correct if the user triggering the event was SSP Admin) and we also see that the name of the SSP Admin is the one returned from this call.

    Basically the steps needed for impersonation are that the code is running as the SSP Admin (which the event service always does – so no problem here) and that the call to web services goes to the SSP location of the web service and not the PWA location (see the code below for examples).  This also needs context setting for the resource and site uid – both of which are available from the contextInfo of the event itself.  The final point is that you need to create web services derived from the Project Server web services that has an override of the WebRequest to add a couple of items to the header.  I used classes already included in the ProjTool sample (in the Utils directory) with very minor changes. 

    Here is the code - and the only other thing you need to know is that you will need to add web references to the LoginWindows, TimeSheet and Statusing web services - and references to the Microsoft.Office.Project.Schema, Microsoft.Office.Project.Server.Library and Microsoft.Office.Project.Server.Events.Receivers.

    I’ve also attached a zip of the two .cs files as I noticed there is some trimming of the longer lines.

    First without impersonation…

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Net;
    using System.Text;
    using Microsoft.Office.Project.Server.Events;
    using PSLibrary = Microsoft.Office.Project.Server.Library;
    
    namespace EventHandlerWithNoImpersonation
    {
        public class MyEventHandler:TimesheetEventReceiver 
        {
            const string LOGINWINDOWS = "_vti_bin/PSI/LoginWindows.asmx";
            const string TIMESHEET = "_vti_bin/PSI/TimeSheet.asmx";
            private static WebSvcLoginWindows.LoginWindows loginWindows =
                new WebSvcLoginWindows.LoginWindows();
            private static WebSvcTimeSheet.TimeSheet timeSheet =
                new EventHandlerWithNoImpersonation.WebSvcTimeSheet.TimeSheet();
            private string baseUrl = "http://servername/cal/"; 
    
            public override void OnCreated(PSLibrary.PSContextInfo contextInfo, 
                TimesheetPostEventArgs e)
            {
                base.OnCreated(contextInfo, e);
    
                loginWindows.Url = baseUrl + LOGINWINDOWS;
                loginWindows.Credentials = CredentialCache.DefaultCredentials;
                timeSheet.Url = baseUrl + TIMESHEET;
                timeSheet.Credentials = CredentialCache.DefaultCredentials;
    
                WebSvcTimeSheet.TimesheetDataSet dsTimeSheet =
                    new EventHandlerWithNoImpersonation.WebSvcTimeSheet.TimesheetDataSet();
                //  As this call is using a specific UID it doesn't require 
                dsTimeSheet = timeSheet.ReadTimesheet(e.TsUID);
                WebSvcTimeSheet.TimesheetDataSet.HeadersRow headersRow = 
                    (WebSvcTimeSheet.TimesheetDataSet.HeadersRow)dsTimeSheet.Headers.Rows[0];
    
                string tsName = headersRow.TS_NAME;
    
                // Create an EventLog instance and assign its source.
                EventLog myLog = new EventLog();
                myLog.Source = "Timesheet Event Handler";
    
                // Get information from the event arguments, and 
                // write an entry to the Application event log. 
                string userName = contextInfo.UserName.ToString();
                string timesheetGuid = e.TsUID.ToString();
                int eventId = 3937;
                string logEntry;
    
                logEntry = "User: " + userName + "\nTimesheet UID: "
                    + timesheetGuid + "\nThis timesheet is called: " + tsName;
                myLog.WriteEntry(logEntry, EventLogEntryType.Information, eventId);
    
    
            }
            
        }
        public class MyEventHandler2 : StatusingEventReceiver
        {
            const string LOGINWINDOWS = "_vti_bin/PSI/LoginWindows.asmx";
            const string STATUSING = "_vti_bin/PSI/Statusing.asmx";
            private static WebSvcLoginWindows.LoginWindows loginWindows =
                new WebSvcLoginWindows.LoginWindows();
            private static WebSvcStatusing.Statusing statusing =
                new EventHandlerWithNoImpersonation.WebSvcStatusing.Statusing();
            private string baseUrl = "http://servername/PWA/";
    
            public override void OnStatusUpdating(Microsoft.Office.Project.Server.Library.PSContextInfo contextInfo, StatusUpdatePreEventArgs e)
            {
                base.OnStatusUpdating(contextInfo, e);
    
                loginWindows.Url = baseUrl + LOGINWINDOWS;
                loginWindows.Credentials = CredentialCache.DefaultCredentials;
                statusing.Url = baseUrl + STATUSING;
                statusing.Credentials = CredentialCache.DefaultCredentials;
    
                WebSvcStatusing.StatusingDataSet dsStatusing =
                    new EventHandlerWithNoImpersonation.WebSvcStatusing.StatusingDataSet();
                dsStatusing = statusing.ReadStatus(Guid.Empty,DateTime.MinValue,DateTime.MaxValue);
                WebSvcStatusing.StatusingDataSet.ResourcesRow resourceRow =
                    (WebSvcStatusing.StatusingDataSet.ResourcesRow)dsStatusing.Resources.Rows[0];
    
    
                int taskCount = dsStatusing.Tasks.Count;
                string statusOwner = resourceRow.RES_NAME;
    
                // Create an EventLog instance and assign its source.
                EventLog myLog = new EventLog();
                myLog.Source = "Statusing Event Handler";
    
                // Get information from the event arguments, and 
                // write an entry to the Application event log. 
                string userName = contextInfo.UserName.ToString();
                string statusingXml = e.ChangeXml;
                int eventId = 3938;
                string logEntry;
    
                logEntry = "User: " + userName + "\nChangeXML: "
                    + statusingXml + "\nThis statusing dataset has " + taskCount
                    + " tasks, and they belong to " + statusOwner;
                myLog.WriteEntry(logEntry, EventLogEntryType.Information, eventId);
    
    
            }
        }
    }
    and then with impersonation…
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Net;
    using System.Text;
    using Microsoft.Office.Project.Server.Events;
    using PSLibrary = Microsoft.Office.Project.Server.Library;
    
    namespace EventHandlerWithImpersonation
    {
        public class MyEventHandlerImp :TimesheetEventReceiver 
        {
            const string LOGINWINDOWS = "LoginWindows.asmx";
            const string TIMESHEET = "TimeSheet.asmx";
           
            
            private string baseUrl = "http://servername:56737/SharedServices1/PSI/";
    
            private static LoginWindowsDerived loginWindows = new LoginWindowsDerived();
            private static TimesheetDerived timeSheet = new TimesheetDerived();
           
            public override void OnCreated(PSLibrary.PSContextInfo contextInfo, TimesheetPostEventArgs e)
            {
                base.OnCreated(contextInfo, e);
                bool isWindowsAccount = contextInfo.IsWindowsUser;
                Guid trackingGuid = Guid.NewGuid();
                string lcid = "1033";
                string userNTAccount = contextInfo.UserName;
                Guid resourceGuid = new Guid(contextInfo.UserGuid.ToByteArray());
                Guid siteId = new Guid(contextInfo.SiteGuid.ToByteArray());
    
                LoginWindowsDerived.SetImpersonationContext(isWindowsAccount, userNTAccount, resourceGuid, trackingGuid, siteId, lcid);
                TimesheetDerived.SetImpersonationContext(isWindowsAccount, userNTAccount, resourceGuid, trackingGuid, siteId, lcid);
    
                
                loginWindows.Url = baseUrl + LOGINWINDOWS;
                loginWindows.Credentials = CredentialCache.DefaultCredentials;
                timeSheet.Url = baseUrl + TIMESHEET;
                timeSheet.Credentials = CredentialCache.DefaultCredentials;
    
                WebSvcTimeSheet.TimesheetDataSet dsTimeSheet =
                    new EventHandlerWithImpersonation.WebSvcTimeSheet.TimesheetDataSet();
                dsTimeSheet = timeSheet.ReadTimesheet(e.TsUID);
                WebSvcTimeSheet.TimesheetDataSet.HeadersRow headersRow = 
                    (WebSvcTimeSheet.TimesheetDataSet.HeadersRow)dsTimeSheet.Headers.Rows[0];
    
                string tsName = headersRow.TS_NAME;
    
                // Create an EventLog instance and assign its source.
                EventLog myLog = new EventLog();
                myLog.Source = "Impersonating Timesheet Event Handler";
    
                // Get information from the event arguments, and 
                // write an entry to the Application event log. 
                string userName = contextInfo.UserName.ToString();
                string timesheetGuid = e.TsUID.ToString();
                int eventId = 3939;
                string logEntry;
    
                logEntry = "User: " + userName + "\nTimesheet UID: "
                    + timesheetGuid + "\nThis timesheet is called: " + tsName;
                myLog.WriteEntry(logEntry, EventLogEntryType.Information, eventId);
    
    
            }
            
    
            
        }
        public class MyEventHandlerImp2 :StatusingEventReceiver
        {
            const string LOGINWINDOWS = "LoginWindows.asmx";
            const string STATUSING = "Statusing.asmx";
    
            private string baseUrl = "http://servername:56737/SharedServices1/PSI/";
    
            private static LoginWindowsDerived loginWindows = new LoginWindowsDerived();
            private static StatusingDerived statusing = new StatusingDerived();
    
            public override void OnStatusUpdating(PSLibrary.PSContextInfo contextInfo, StatusUpdatePreEventArgs e)
            {
                base.OnStatusUpdating(contextInfo, e);
    
                bool isWindowsAccount = contextInfo.IsWindowsUser;
                Guid trackingGuid = Guid.NewGuid();
                string lcid = "1033";
                string userNTAccount = contextInfo.UserName;
                Guid resourceGuid = new Guid(contextInfo.UserGuid.ToByteArray());
                Guid siteId = new Guid(contextInfo.SiteGuid.ToByteArray());
    
                LoginWindowsDerived.SetImpersonationContext(isWindowsAccount, userNTAccount, resourceGuid, trackingGuid, siteId, lcid);
                StatusingDerived.SetImpersonationContext(isWindowsAccount, userNTAccount, resourceGuid, trackingGuid, siteId, lcid);
    
    
                loginWindows.Url = baseUrl + LOGINWINDOWS;
                loginWindows.Credentials = CredentialCache.DefaultCredentials;
                statusing.Url = baseUrl + STATUSING;
                statusing.Credentials = CredentialCache.DefaultCredentials;
    
                WebSvcStatusing.StatusingDataSet dsStatusing =
                    new EventHandlerWithImpersonation.WebSvcStatusing.StatusingDataSet();
                dsStatusing = statusing.ReadStatus(Guid.Empty, DateTime.MinValue, DateTime.MaxValue);
                WebSvcStatusing.StatusingDataSet.ResourcesRow resourceRow = 
                    (WebSvcStatusing.StatusingDataSet.ResourcesRow)dsStatusing.Resources.Rows[0];
    
    
                int taskCount = dsStatusing.Tasks.Count;
                string statusOwner = resourceRow.RES_NAME;
    
                // Create an EventLog instance and assign its source.
                EventLog myLog = new EventLog();
                myLog.Source = "Impersonating Statusing Event Handler";
    
                // Get information from the event arguments, and 
                // write an entry to the Application event log. 
                string userName = contextInfo.UserName.ToString();
                string statusingXml = e.ChangeXml;
                int eventId = 3940;
                string logEntry;
    
                logEntry = "User: " + userName + "\nChangeXML: "
                    + statusingXml + "\nThis statusing dataset has " + taskCount 
                    + " tasks, and they belong to " + statusOwner;
                myLog.WriteEntry(logEntry, EventLogEntryType.Information, eventId);
    
            }
        }
        class LoginWindowsDerived : WebSvcLoginWindows.LoginWindows
        {
            private static String ContextString = String.Empty;
    
            protected override WebRequest GetWebRequest(Uri uri)
            {
                //here we are overriding the GetWebRequest method and adding the 2 web request headers
                WebRequest webRequest = base.GetWebRequest(uri);
                if (ContextString != String.Empty)
                {
                    webRequest.UseDefaultCredentials = true;
    
                    bool isImpersonating = (System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
                    webRequest.Credentials = CredentialCache.DefaultNetworkCredentials;
    
                    webRequest.Headers.Add("PjAuth", ContextString);
                    webRequest.Headers.Add("ForwardFrom", "/_vti_bin/psi/LoginWindows.asmx");
    
                    webRequest.PreAuthenticate = true;
                }
                return webRequest;
            }
    
            public static void SetImpersonationContext(bool isWindowsUser, String userNTAccount, Guid userGuid, Guid trackingGuid, Guid siteId, String lcid)
            {
                ContextString = GetImpersonationContext(isWindowsUser, userNTAccount, userGuid, trackingGuid, siteId, lcid);
            }
    
            private static String GetImpersonationContext(bool isWindowsUser, String userNTAccount, Guid userGuid, Guid trackingGuid, Guid siteId, String lcid)
            {
                PSLibrary.PSContextInfo contextInfo = new PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid, trackingGuid, siteId, lcid);
                String contextString = PSLibrary.PSContextInfo.SerializeToString(contextInfo);
                return contextString;
            }
        }
        class TimesheetDerived : WebSvcTimeSheet.TimeSheet 
        {
            private static String ContextString = String.Empty;
    
            protected override WebRequest GetWebRequest(Uri uri)
            {
                //here we are overriding the GetWebRequest method and adding the 2 web request headers
                WebRequest webRequest = base.GetWebRequest(uri);
                if (ContextString != String.Empty)
                {
                    webRequest.UseDefaultCredentials = true;
    
                    bool isImpersonating = (System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
                    webRequest.Credentials = CredentialCache.DefaultNetworkCredentials;
    
                    webRequest.Headers.Add("PjAuth", ContextString);
                    webRequest.Headers.Add("ForwardFrom", "/_vti_bin/psi/timesheet.asmx");
    
                    webRequest.PreAuthenticate = true;
                }
                return webRequest;
            }
    
            public static void SetImpersonationContext(bool isWindowsUser, String userNTAccount, Guid userGuid, Guid trackingGuid, Guid siteId, String lcid)
            {
                ContextString = GetImpersonationContext(isWindowsUser, userNTAccount, userGuid, trackingGuid, siteId, lcid);
            }
    
            private static String GetImpersonationContext(bool isWindowsUser, String userNTAccount, Guid userGuid, Guid trackingGuid, Guid siteId, String lcid)
            {
                PSLibrary.PSContextInfo contextInfo = new PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid, trackingGuid, siteId, lcid);
                String contextString = PSLibrary.PSContextInfo.SerializeToString(contextInfo);
                return contextString;
            }
        }
        class StatusingDerived : WebSvcStatusing.Statusing
        {
            private static String ContextString = String.Empty;
    
            protected override WebRequest GetWebRequest(Uri uri)
            {
                //here we are overriding the GetWebRequest method and adding the 2 web request headers
                WebRequest webRequest = base.GetWebRequest(uri);
                if (ContextString != String.Empty)
                {
                    webRequest.UseDefaultCredentials = true;
    
                    bool isImpersonating = (System.Security.Principal.WindowsIdentity.GetCurrent(true) != null);
                    webRequest.Credentials = CredentialCache.DefaultNetworkCredentials;
    
                    webRequest.Headers.Add("PjAuth", ContextString);
                    webRequest.Headers.Add("ForwardFrom", "/_vti_bin/psi/statusing.asmx");
    
                    webRequest.PreAuthenticate = true;
                }
                return webRequest;
            }
    
            public static void SetImpersonationContext(bool isWindowsUser, String userNTAccount, Guid userGuid, Guid trackingGuid, Guid siteId, String lcid)
            {
                ContextString = GetImpersonationContext(isWindowsUser, userNTAccount, userGuid, trackingGuid, siteId, lcid);
            }
    
            private static String GetImpersonationContext(bool isWindowsUser, String userNTAccount, Guid userGuid, Guid trackingGuid, Guid siteId, String lcid)
            {
                PSLibrary.PSContextInfo contextInfo = new PSLibrary.PSContextInfo(isWindowsUser, userNTAccount, userGuid, trackingGuid, siteId, lcid);
                String contextString = PSLibrary.PSContextInfo.SerializeToString(contextInfo);
                return contextString;
            }
        }
        
    }
    Enjoy!
Page 77 of 97 (483 items) «7576777879»