locked
workflow with anonymous access RRS feed

  • Question

  • We have a Request for Information form that can be accessed anonymously and the anonymous users have add and view priveleges. What we want is when the user submits the form to have a workflow kick off that sends an email to the user who submitted the form using the email address within the form data and also send an email to an administrator.

    However, we are seeing some problems with anonymous users and workflow playing nice together.

    ·         If a user is logged in (windows authentication), then the form works as expected, the data is stored in the database, the user is directed to the appropriate page and the workflow runs.

    ·         If no workflow is tied to the list, the anonymous user can submit their request for information as expected. The data goes into the database and the user is directed to the appropriate page.

    ·         If a workflow is attached to the list, the user can still submit their request and the data makes it into the database. However, the user remains on the same page and the error below is displayed.

    The data source control failed to execute the insert command.

     

    Web Parts Maintenance Page: If you have permission, you can use this page to temporarily close Web Parts or remove personal settings. For more information, contact your site administrator.

     

    Troubleshoot issues with Windows SharePoint Services.

    Is there something else that needs to be done to enable workflows to work with anonymous users?

    Thanks

    Tuesday, February 13, 2007 1:29 AM

All replies

  • It turns out that the workflow runs as the currently logged in user. At this point, there is not a way to have the workflow run if it is kicked off by an anonymous user.
    Wednesday, February 21, 2007 5:32 PM
  • As well, even if you don't set the workflow to auto-start ... it still throws the exception (it's actually an "Out of Memory" exception that gets thrown ... apparently according to Microsoft Support it is because it tries to retrieve the user object and there is none)

    I'm trying to come up with a work around right now as I've been advised that they're not planning on fixing this with a hot fix but rather we will have to wait to have it fixed in the 1st service pack.

    Friday, March 16, 2007 1:19 PM
  • Thinking off the top of my head here, so I haven't tested this...could you have an event receiver kick off for the item, check if the user is named or anonymous and then either:

    1. launch the workflow (if user is named)

    2. Do some impersonation and then launch the workflow (if anonymous)

    As I said, never tried event receivers on anonymous, you may have the same problem.

    -Dave

    Monday, March 19, 2007 1:42 AM
  • I've now also tried using a custom event receiver and tried handling the ItemAdding event, however, attaching an event receiver to a list results in exactly the same behaviour as attaching a workflow (OutOfMemoryException)!

    (The only difference is that with the event handler, since it throws the error sooner, the item doesn't actually get added, whereas with the workflow, the item gets added, and then the error is thrown)

     

    Tuesday, March 20, 2007 1:59 PM
  • Ok.  I've created a workaround for this issue since Microsoft will not be providing a fix until SP1 of SharePoint.  Basically what I've done is as follows:

    1. Create a custom content type that inherits from the "Custom List" content type (you could also use any other content type to derive from).  You don't need to define any additional fields unless you want.  I'm just using a basic custom list and then adding fields at runtime.
    2. With the content type, create a custom rendering template (ascx file to be placed in control templates) that is almost the same as the ListForm template found in "DefaultTemplates.ascx" (the default form used to render list items).
    3. Modify the custom rendering template by removing the SharePoint save button and adding an ASP.NET button that posts back.  Handle the button's OnLoad event to set it's visibility and handle the button's OnClick event to save the item.
    4. To save the item in the OnClick event, use the "SPSecurity.RunWithElevatedPriviliges".
    5. Package all of this in a solution and feature and deploy to your site.  You can then create lists that use this content type to allow anonymous users to add items that have workflows or event handlers attached to them.

     

    Tuesday, March 20, 2007 5:14 PM
  • any chance you have the source to your solution available somewhere?
    Friday, April 20, 2007 8:31 PM
  • Is there any way you can give more specific instruction on this? I am desparate at this point...
    Friday, April 27, 2007 10:28 PM
  • Hi, would anyone provide the tailored template? I found trouble in implementing the onclick event to save the item.

    Please, Please ....

    Thursday, May 17, 2007 1:37 AM
  • Joe,

     

    is it possible for you to post more details about that workaround?

     

    If so, I would be your oblidged.

     

    Regards

    Gilles

     

    Wednesday, November 7, 2007 9:22 PM
  • Deleted
    Monday, August 4, 2008 4:29 AM
  • See this post and the others on my blog for step-by-step instructions on one way to resolve this issue.

    Easy WSS Forms with Workflow and Anonymous Access

    Since I wrote the original posts about using an anonymous membership provider, Reza Alirezaei did a much better job and even created a solution package. He has a series of articles here: http://blogs.devhorizon.com/reza/?p=498

    --Doug Ware
    http://www.elumenotion.com/blog
    • Proposed as answer by Doug WareMVP Wednesday, August 6, 2008 9:28 PM
    • Unproposed as answer by Mike Walsh FIN Saturday, May 9, 2009 7:48 AM
    Tuesday, August 5, 2008 2:34 AM
  • Hi,
    I had exact issue like you and the what worked for me was impersonating the anonymous user.
    Create a user or you can use an existing user .. make sure you have given Write permissions on the list to which workflow is attached to, to the user as code will execute under the identity of the user you are impersonating.
    Workflows do not get started by anonymous user and code to impersonate it is

    1   SPSecurity.RunWithElevatedPrivileges(delegate() 
    2            { 
    3            using(SPSite site = new SPSite(SPContext.GetContext(System.Web.HttpContext.Current).Site.Url)) 
    4            { 
    5             
    6            using (SPWeb parentWeb = site.OpenWeb()) 
    7            { 
    8                string userName = ConfigurationManager.AppSettings["contactUsUser"]; 
    9                SPUser user = parentWeb.AllUsers[userName]; 
    10////YOU CAN ALSO HARD CODE THE USER AS BELOW 
    11                //SPUser user = parentWeb.AllUsers["DOMAIN\\USER_NAME"]; 
    12                SPUserToken token = user.UserToken; 
    13 
    14                using (SPSite s = new SPSite(SPContext.Current.Site.Url, token)) 
    15                { 
    16                    using (SPWeb web = s.RootWeb) 
    17                    { 
    18DO YOUR LOGIC HERE 
    19                    } 
    20                } 
    21 
    22            } 
    23             
    24            } 
    25        }); 
    26 
    Hope this helps.

    Ajay Khanna
    • Proposed as answer by AjayKhanna Saturday, September 13, 2008 11:28 AM
    • Edited by AjayKhanna Saturday, September 13, 2008 11:30 AM
    • Unproposed as answer by Mike Walsh FIN Saturday, May 9, 2009 7:48 AM
    • Proposed as answer by Mohamed Sharaky Monday, August 10, 2009 11:14 AM
    • Unproposed as answer by Mike Walsh FIN Tuesday, May 4, 2010 6:05 AM
    Saturday, September 13, 2008 11:27 AM
  • Hi!

    How I can make following scenario works:
    Anonymous user creates Request (Custom List) and Workflow (Make to-do item assigned to some user) is started?

    I've created EventHandler and try to debug it. Breakpoint even doesn't happen for anonymous user - Server Out Of Memory is returned.

    [OutOfMemoryException: Server Out Of Memory  
     
    There is no memory on the server to run your program. Please contact your administrator with this problem.]  
       Microsoft.SharePoint.Library.SPRequestInternalClass.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish) +0  
       Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish) +203  
       Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSystem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boolean bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32& ulID, Object& objAttachmentNames, Object& objAttachmentContents, Boolean suppressAfterEvents) +825  
       Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents) +166  
       Microsoft.SharePoint.SPListItem.Update() +94  
       Microsoft.SharePoint.WebControls.SaveButton.SaveItem(SPContext itemContext, Boolean uploadMode, String checkInComment) +303  
       Microsoft.SharePoint.WebControls.SaveButton.SaveItem() +71  
       Microsoft.SharePoint.WebControls.SaveButton.OnBubbleEvent(Object source, EventArgs e) +277  
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37  
       System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118  
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166  
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10  
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13  
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175  
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565  
     
       
     
     
    For System Account and other users event fires, but Workflow (which runs ok with manual initiation) falls with error (but it is another story I think).

    Here is ItemAdded Event Receiver made with VS extensions for Sharepoint 1.2

        public override void ItemAdded(SPItemEventProperties properties)  
            {  
                // Change check method  
                if (properties.ListTitle != "Requests") return;  
     
                SPSecurity.RunWithElevatedPrivileges(delegate()  
                {  
                    using (SPWeb contextWeb = properties.OpenWeb())  
                    {  
                        // Change user selection method  
                        // string userName = ConfigurationManager.AppSettings["contactUsUser"];    
                        // SPUser user = parentWeb.AllUsers[userName];    
                        SPUser user = contextWeb.AllUsers["LITWAREINC\\ClausH"];  
                        SPUserToken token = user.UserToken;  
     
                        using (SPSite impersonatedSite = new SPSite(properties.SiteId, token))  
                        {  
                            SPList requests = contextWeb.Lists[properties.ListId];  
                            impersonatedSite.WorkflowManager.StartWorkflow(  
                                   properties.ListItem,  
                                   //Change workflow selection method using ID  
                                   requests.WorkflowAssociations[0],  
                                   String.Empty);  
                        }  
                    }  
                });  
            } 
    Monday, December 29, 2008 6:21 AM
  • Mr. Sergey,
                      do you find a solution or any workaround for this scenario.? 
    Mohamed Qasem
    Sunday, May 17, 2009 6:26 AM
  • Qasem,

             You can try this option : http://wssguestaccount.codeplex.com/

     

    by default you will be logged in as guest account, so can avoid the anonymous user restrictions.

    I ran across the same issue, but my workflow is simple notification workflow, I resolved the problem by tweeking the design with some custom timer jobs.


    Thanks,
    ~Uday

    Monday, May 3, 2010 7:13 PM
  • Thanks Alot for you support (F)
    Mohamed Qasem
    Friday, May 7, 2010 5:39 PM