.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Not able to get current windows user in RS2005 (but same code works for RS2000)

Posted By:      Posted Date: October 12, 2010    Points: 0   Category :Sql Server

We use the following custom code (checkGroupMembership.dll) to get identity of the current windows user and then check if the user is part of a certain group (roleName in code below).  

SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.ControlPrincipal);
WindowsIdentity wi = WindowsIdentity.GetCurrent();
WindowsPrincipal cPrincipal = new WindowsPrincipal(wi);    
isMember = cPrincipal.IsInRole(roleName);

The code above behaves differently for RS2000 vs. RS2005. Both RS2000 and RS2005 are installed on same server. If I use the following code to check the WindowsPrincipal name, I get the expected result (my windows login ID) when called from a report in RS2000 but for RS2005 I get the user id of reporting services.


I have checked rssrvpolicy.config (for both RS2000 and RS2005) and it has the same permission for checkGroupMembership.dll.

Any suggestions on why the same code will get different WindowsIdentity? Where I should look next? Any help would be greatly appreciated.


View Complete Post

More Related Resource Links

Get the current user without writing code

i have a question regarding the "Get the current user without writing code" tutorial. http://blogs.microsoft.co.il/blogs/itaysk/archive/2007/04/05/InfoPath-_2D00_-Get-the-current-user-without-writing-code.aspx?from=ClayCobb the url that i have to enter in the web service details is not working for me. do i have to use the same url for wss 3 also? maybe i have to ask this: can this be used for sharepoint services 3.0? i have enter: http://servername:portnumber/_vti_bin/UserProfileService.asmx  when i open it in a browser it gives me the sharepoint error page and when i insert the url in infopath it gives me this error: the file is not a valid XML file. The form contains XML that cannot be parsed: a string literal was expected, but no opening quote character was found. Line 19,position 38 <TABLE class="ms-main" CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH="100%" HEIGHT="100%">

How to get current user session in Windows application C#?



I am trying to create a Windows Application similar to facebook friend finder.exe in .NET. The steps I have followed to achieve this is as follows:

1. I have created a webservice containing webmethod SaveContacts(string firstname, string lastname, string number, string photo, string email, string userid).


2. I am consuming the webservice in a Windows Form application and calling the above mentioned function.

Now, I want to get the current logged in user ID which through the windows form application which is something tedious to me.

If anyone have any idea how to achieve this. Please help.






Windows Service crashing on call to unmanaged code, even though console app version works


I have a C# program that at some point calls 2 functions from an unmanaged dll using p/invoke.  Everything works fine when I'm running in a console app.  When I compile the same program as a windows service and run it, it crashes.  The console app and service should be identical as far as my code is concerned... all either program does is create an object from another assembly of mine and run a Start() method on it.

I have used VS2010 to debug the managed and unmanaged code, and when I step through the Console app everything looks great.  When I attach the debugger to the service, i can step through the first function in the unmanaged code, control returns to the managed code, and then later when it comes to the point where it calls the second unmanaged function, the process terminates immediately before the debugger steps into the first line of unmanaged code.  There are no exceptions that I can see, and the only thing written to the event log is the generic "service terminated unexpectedly" message.  Running "sc query" on the command line lets me know the win32_exit_code is 1067.

Im running everything in .net 4, on winxp 32bit.  The serivce is running as Local System ideally, but the same behavior exists when I run it under my user account. 

Adding Current Windows User to Database Encounters Existing User with Same Login


In VS2008 in debug mode, I am using SMO to programatically change the users and permissions on a database. Windows authentication alone is being used. I need to limit access to a administrators group and the current user for whom the database has been dynamically created during the first run of the application within their current Windows environment on the machine. I have no problems creating and assigning the administrators group, but when I try to create the user using the environment's UserDomainName and UserName variables (which would be my creditals) I encounter an inner exception "The login already has an account under a different user name". Before doing running the app, I manually have checked the local server for user and logins with my credentials and programatically looked at each login but have not found any matching credentials. 

Insights and suggestions appreciated.


How to get WIndows Current User without Anonymus Access


Hi All,

We have developed an web application, that should run with Active Directory users. That is working fine in our local machines, but when we hosted this into client environment, we are unable to  get the Current User, it is returning NULL.

Could you please give a solution to us.


Thanks in Advance,

Sateesh Nagalla. 

DirectorySecurity / calculating effective rights for the current windows user?


How do you calculate the effective rights for the current windows user and a specified directory?  I see how you can retrieve the DACL for a Directory using: Directory.GetAccessControl.  

I see that you can get all the access rules for the DACL using: 

var authRules = myDirectorySecurity.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));


This seems to return all acess control entries for the given DACL.  I need to determine the effective rights for the current windows user against a give directory.

How can I retrieve or calculate the effective rights for a given user on a given folder? I basically need to determine if the current windows user has read/write/delete permissions for a given folder.


















Creating Sites/Lists/List Items under Current User Context in SharePoint By Using SPUserToken

Usually we do this by performing the action under RunWithElevatedPrivileges method and updating the listitem using SPListItem.SystemUpdate() method (see here). but this approach has its own flaws like (RunWithElevatedPrivileges will run under system account, we cannot use SystemUpdate for SPSite,SPWeb,SPList, since it runs under system we will "CreatedBy" by as SystemAccount).

Code works on aspx but not ascx


Not sure which category to put this question in, so I will put it in here.

Just to give you an idea of the layout of my solution, I have the main project, along with 2 class libraries, BLL and DAL.  (Business Logic Layer and Data Access Layer)

The BLL refers to the DAL and the main project refers to the BLL.

I had a test website and the code worked fine, but the same code will not work on the real project. The only difference is that in the test project, the code was on an aspx code behind, whereas in the real project, it is an ascx code behind (Web User Control )

The code is:

Dim connectionString As String = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ConnectionString
        Dim recordEntry As New UserRecord(connectionString)
        recordEntry.UserName = "TestName"
        recordEntry.BMI = bMI
        recordEntry.BMR = bMR
        recordEntry.FTM = fTM
        recordEntry.TDEE = tDEE
        recordEntry.TodayDate = dateForToday

Dim connectionString As String = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ConnectionString

No ASPNET User in Windows Server 2008?


I have been looking everywhere online regarding this, but have not found a clear answer.


I have an ASP.Net app running on Windows Server 2008, it's basically a reporting app using Crystal Reports. I have encountered a roadblock in regards to rendering some pages. When I run the app in Visual Studio(on the same 2008 machine) everything works perfectly. Yet when I publish it and run it live the reports will not display correctly, I get a message saying Failed to render page.


I looked this error up in the Crystal Reports website and the fixes they have there refer to giving the windows "aspnet" user full access rights to certain folders on the machine. I would be happy to do this, however there is no aspnet user in Windows Server 2008.


I installed the server and set its role to be Web Server. I also checked all the options regarding ASP.Net and IIS 6 compatibility. Yet there is no ASPNET username anywhere.


Did I set the server up wrong? or do I have to do something within ASP.Net to  create this user and then give it rights? 

Least Privilege: Teach Your Apps To Play Nicely With Windows Vista User Account Control


User Account Control in Windows Vista keeps the OS safe from intentional and accidental configuration changes.

Chris Corio

MSDN Magazine January 2007

Smart Storage: Protect Your Data Via Managed Code And The Windows Vista Smart Card APIs


Smart cards are a compelling alternative to the reliance on passwords, which are the weakest link in authentication systems. Get the Windows smart card programming basics here.

Dan Griffin

MSDN Magazine November 2006

App Fundamentals: Build A Great User Experience With Windows Presentation Foundation


The Windows Presentation Foundation application model distinguishes between standalone and browser applications and between menu driven and hyperlink driven navigation, resulting in a more satisfying experience for your users.

Michael Weinhardt

MSDN Magazine October 2006

ASP.NET: Combine Web and Windows Services to Run Your ASP.NET Code at Scheduled Intervals


If you want to schedule ASP.NET tasks, one solution is to use a Web service to provide an interface to your ASP.NET application and build a Windows service that calls to it at scheduled intervals. Thus the ASP.NET application doesn't have to own the scheduling logic. Here the author shows how to schedule your ASP.NET tasks using a Windows service to initiate the Web service call because Windows services can start themselves when Windows boots up.

Andrew Needleman

MSDN Magazine March 2005

Code Name Longhorn: A First Look at Writing and Deploying Apps in the Next Generation of Windows


The next version of the Microsoft Windows operating system, code-named "Longhorn," marks a significant change not only in terms of how the operating system works, but also in the way in which applications are built. The Longhorn version of Windows includes a new storage system, natural search technology, and an increased emphasis on security and trustworthy computing. Here the author provides an overview of Longhorn, focusing on the build-once, deploy n-times application model. In addition, he discusses the new language, code-named "XAML," that's used to create UI elements, then presents some working samples.

Dino Esposito

MSDN Magazine January 2004

Threading: Break Free of Code Deadlocks in Critical Sections Under Windows


Critical sections, a mechanism that prohibits more than one thread at a time from executing a particular section of code, is a topic that has not received much attention and thus tends not to be well understood. A solid understanding of critical sections in Windows can really come in handy when you need to track down multithreading performance issues in your code. This articles delves under the hood of critical sections to reveal information useful in finding deadlocks and in pinpointing performance problems. It also includes a handy utility program that shows all of your critical sections and their current states.

Matt Pietrek and Russ Osterlund

MSDN Magazine December 2003

Debug: Detect and Plug GDI Leaks in Your Code with Two Powerful Tools for Windows XP


In a previous article, the author devised a simple method to detect Graphical Device Interface (GDI) objects that are not properly released by Win32-based applications on Windows 9x platforms. Because some newer versions of Windows require a slightly different approach to GDI leaks, the author has updated his techniques for those operating systems. He builds and explains two tools designed to detect and eradicate GDI leaks in applications running on Windows XP, Windows 2000, and Windows NT.

Christophe Nasarre

MSDN Magazine January 2003

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend