Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Getting the correct UserId in a Domain Environment @BusinessRules_UserId @BusinessRules_UserName

I'm posting this here in the hopes that it might help someone else who runs into issues getting the correct UserId for use inside SQL filters while on a Windows domain. @BusinessRules_UserId and @BusinessRules_UserName did not work for me but extending via App_Code/custom/Rules/SharedBusinessRules.cs did.

Just replace YOURNAMESPACE with the one in your project.


using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using YOURNAMESPACE.Data;
using System.Web.Security;

namespace YOURNAMESPACE.Rules
{
public partial class SharedBusinessRules : YOURNAMESPACE.Data.BusinessRules
{

public SharedBusinessRules()
{
}

public static string RealUserID
{
get
{

MembershipUser user = Membership.GetUser(System.Web.HttpContext.Current.User.Identity.Name, true);
var userId = user.ProviderUserKey;
return userId.ToString();
}
}

}

}


Now in your sql filters you can use the variable @BusinessRules_RealUserID

Sifting through CoT "documentation" vaguely helped in getting this done. I do still wish there was an accurate list of exposed variables that can be used in Sql filters available but now that I see how to add my own I suppose its moot.

I hope this saves someone else some frustration.
1 person likes
this idea
+1
Reply