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)

Syntax

'Declaration
Public Property ReturnsPersonalInformation As Boolean
    Get
    Set
'Usage
Dim instance As UdfMethodAttribute
Dim value As Boolean

value = instance.ReturnsPersonalInformation

instance.ReturnsPersonalInformation = value
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.

Remarks

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.

Examples

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);
        }
    }
}

See Also

Reference

UdfMethodAttribute Class

UdfMethodAttribute Members

Microsoft.Office.Excel.Server.Udf Namespace