locked
Is there a Context.Current.User property in WF? RRS feed

  • Question

  • Our WF uses web services automatically created by WF.  For logging (verbose) I want to be able to log when a user is calling a WebServiceInput...where (if it does) does the web service pass the IIS user name info into the workflow?  The point is for auditing, I want to be able to track what user is doing what or how often they're calling the workflow.
    Thursday, January 10, 2008 2:40 PM

Answers

  • No, WF doesn't have a Context.Current.User property, or anything similar to get the current user.  However you could create a dummy WorkflowRole for each web service that you use and in the IncludesIdentity method you could trace out the user and the web service name, something like the following:

     

    public class DummyRole : WorkflowRole

    {

        string webServiceName;

     

        public DummyRole(string webServiceName)

        {

            this.webServiceName = webServiceName;

        }

     

        public override IList<string> GetIdentities()

        {

            return new List<string>();

        }

     

        public override bool IncludesIdentity(string identity)

        {

            Console.WriteLine("User {0} is accessing web service {1}", identity, this.webServiceName);

            return true;

        }

     

        public override string Name

        {

            get

            {

                return this.webServiceName;

            }

            set

            {

                this.webServiceName = value;

            }

        }

    }

     

    Then just add this dummy role to the WebServiceInputActivity’s Roles collection and set the web service’s name.

    Friday, January 11, 2008 8:58 PM

All replies

  • No, WF doesn't have a Context.Current.User property, or anything similar to get the current user.  However you could create a dummy WorkflowRole for each web service that you use and in the IncludesIdentity method you could trace out the user and the web service name, something like the following:

     

    public class DummyRole : WorkflowRole

    {

        string webServiceName;

     

        public DummyRole(string webServiceName)

        {

            this.webServiceName = webServiceName;

        }

     

        public override IList<string> GetIdentities()

        {

            return new List<string>();

        }

     

        public override bool IncludesIdentity(string identity)

        {

            Console.WriteLine("User {0} is accessing web service {1}", identity, this.webServiceName);

            return true;

        }

     

        public override string Name

        {

            get

            {

                return this.webServiceName;

            }

            set

            {

                this.webServiceName = value;

            }

        }

    }

     

    Then just add this dummy role to the WebServiceInputActivity’s Roles collection and set the web service’s name.

    Friday, January 11, 2008 8:58 PM
  • Implementing the above all I get for 'identity' is string.Empty.

    I literally copied and pasted your code.  In the workflow I have bound the roles collection as you said to the following field:

    public WorkflowRoleCollection webServiceInputActivity1_Roles1 = new System.Workflow.Activities.WorkflowRoleCollection();


    And you didn't say to, but it made since I added the following to the constructor:


    public TestWorkflow()
            {
                InitializeComponent();
                //Add role to collection
                webServiceInputActivity1_Roles1.Add(new DummyRole(this.Name));
            }
    Tuesday, January 15, 2008 3:09 PM
  • It seems to work without manually adding the role to the collection, but the identity is always blank.  Regardless whether I use IWA, Basic, or Digest, no IIS authentication is being passed to the WF.

    Everything I'm finding on this WorkflowRole stuff (which isn't much other than links to MSDN documentation that tell you the class name, property names, and nothing useful), seems to suggest that the use of this class isn't for workflow generated web services.  That the only way that you can do authentication is to write the WF as a regular workflow and then create you're own hand rolled web service to wrap the work-flow and create a SOAP header for it.

    Would you agree with this?
    Tuesday, January 15, 2008 3:29 PM
  • Hi,

     

    I don't clear the relationship between your webservice and WF.

     

    But if you want to get the current login user in the workflow ,you can use follow method:

     

    You can use onTaskChanged1.Executor to get the current login user. But before you use this property, you should defined a public string var ,such as curUser.Then assign curUser to the onTaskChanged1.Executor. 

    Monday, January 28, 2008 6:38 AM