UdfMethodAttribute.ReturnsPersonalInformation Property

Specifies that the user-defined function (UDF) method may return information based on the current user executing the session.

Namespace:  Microsoft.Office.Excel.Server.Udf
Assembly:  Microsoft.Office.Excel.Server.Udf (in Microsoft.Office.Excel.Server.Udf.dll)

public bool ReturnsPersonalInformation { get; set; }

Property Value

Type: System.Boolean
If false, Excel Calculation Services hides the user identity. If true, Excel Calculation Services makes sure that the thread's current principal has the right value before calling the UDF. The default is false.

A UDF that sets this property to true can use the Name property of the System.Threading.Thread.CurrentPrincipal.Identity interface, to get the name of the user on whose behalf the code is running.

  • For ReturnsPersonalInformation=false, Excel Calculation Services hides the user identity by setting the thread's current principal to an empty principal.

  • For ReturnsPersonalInformation=true, Excel Calculation Services makes sure that the thread's current principal has the right value before calling the UDF.

For recalculation, a UDF that is marked as returning personal information (that is, ReturnsPersonalInformation=true) is always called again when previous results do not exist for the same user.

If you need to be able to access the identity of the user who is executing the request on a session (and thus executing the UDF) or the thread identity, set the ReturnsPersonalInformation property to true.

It is important to set this property to true even in cases where you are not explicitly referring to thread identity. For example, if you are acquiring personal information from a database using integrated security, or some other way to get user-specific information, you want the correct caching to be done, and therefore you should set this property to true.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Excel.Server.Udf;
using System.Web;
using System.Security.Principal;

namespace DatabaseAccessUdfsReturnPersonalInformation
{
    [UdfClass]
    public class DatabaseAccessUdfs 
    {
        [UdfMethod(ReturnsPersonalInformation=true)]
        public string GetUserName()
        {
            return 
              (System.Threading.Thread.CurrentPrincipal.Identity.Name);
        }
    }
}

Community Additions

ADD
Show: