.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

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

Posted By:      Posted Date: October 09, 2010    Points: 0   Category :SharePoint


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.






View Complete Post

More Related Resource Links

Oulook.exe hangs when Domain User launches application through Interop windows 2003 sp2

Hello,I have a problem using Interop.Outlook on a win2k3 sp2 server. For windows 2003 version prior to sp1 i could use a specific identity for application pool and i had no problems launching outlook.User was authenticated and delegated correclty. With sp2 the Outlook.exe process is launched by the domain user specified as identity (also visible on Task Manager Processes) but no exception or time out is ever thrown.  The only way that i can make this to work is when i set impersonate=true in web config (without setting userName and password as this would have exactly the same affect with the application pool identity).Are there any permissions that i can set to overcome this?Help would be greatly appreciated. Normal 0 false false false EL X-NONE X-NONE Appreciate

general error login failed for user '' on windows 2008 in application that runs correctly on windo



we have a web application that one company prepared for us. this application read connection string from registery key in hkey_local_machine and connect to sql server 2005 database.

It worked correctly in windows server 2003. we changed our Server'OS to windows server 2008. but we have a problem to login. after try to login we see this error :

Login failed for user ''. The user is not associated with a trusted SQL Server connection.

Server Error in '/dabir' Application.

Login failed for user ''. The user is not associated with a trusted SQL Server connection.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user ''. The user is not associated with a trusted SQL Server connection.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be

adding windows user control in asp.net application


hi fri i had created one user control in c# and i want to add this user control in asp.net application pl tel me how to do this

thanks in advance

Problem hosting a WPF user control in a windows form application

I have a windows forms application and want to to use WPF inside this application. So I have add a WPF user control into my project. Then I take a ElementHost from the toolbox and put it on my windows forms. The problem is now, when I want to add the WPF control with "Edit Host Content" I get the message "This ElementHost is currently not hosting any editable content....." What's wrong? How can I embed my implemented WPF control into the ElementHost ?

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


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.


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. 

How to hide SQL Server password from user in an Windows Forms Application?


Using - VS 2005, SQL Server 2005 Express, Windows Forms Application


I am unable to find a way that hides the password to connect to database in case of a Windws Forms Application.

- app.config is accessible to the user, so connection strings an be read.

- app.config can't be encrypted as in case of ASP.NET applications

- hardcoding the password in the application in connectionstring still makes it possible to be discovered by a user

Vibhor Agarwal

how to maintain session for multi user application


I am developing a web application. This application is fully customised based on the user settings. Suppose, application hosted on www.abc.com and user can signup on the website and it will get the domain like www.user1.abc.com and for user2 will be www.user2.abc.com so and so forth. so in this case how would I maintain the session for each user?

each user will be representing a single website along with public interface and admin pages. 

what I am thinking is to store all the setting (for each user) in the database and then when ever server received request then get the user info from the URL (first time only and after get it from the session) and get user details but I am not very much satisfied with this approach. 

could anyone recommend me any better way to perform this task please? 


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.


















how to authenticate windows user login in my windows application?


i am using .net 3.5 and c#.

i need to implement a login screen on my windows application (not asp.net). the user can be any windows user on the network. i don't need to get password from the domain/system but just need to verify true or false.

please let me know where i should start and what to look into.



1 + 1 = 3

Run windows application as another user



VS2010, C#,Win XP


I am trying to force an application to always run as another user. Even when the user double clicks the exe it should run as a specific other user on the system.


I tried switching the CurrentPrincipal value of the thread that the application runs on by taking the token from LogonUser. Although that did not return an error, it still did not seem to be running as the other spcified user.


Please help

MS SQL Server: Disconnect Users From Database - Kill User Session

If you ever wanted to restore your database from a SQL backup file (.bak), but there are still users connected to your database, the backup operation will fail causing the error: Exclusive access could not be obtained because the database is in use.

Application Architecture in Windows Forms 2.0

Applications have special support in Windows Forms. For starters, you can manage and tailor your application's lifetime, and, when the work flow is disrupted by an unhandled exception, you can choose from several methods of response. Then, there are several application models that you can employ, including Single Document Interface (SDI) and Multiple Document Interface (MDI) applications, each of which can support either multiple-instance or single-instance mode, the former the VS05 default and the latter requiring special consideration. All applications, however, can discover and use a wide variety of information about the system and environment they execute in.

Application Architecture in Windows Forms 2.0-Single-MDI Applications

Consider an MDI application like Microsoft Excel; files opened from the file system (by double-clicking) are all opened as separate child windows within the parent Excel window.7 For the first instance of an MDI application to open a new child window to display the file that was passed to the second instance of the application, the second instance must be able to communicate with the initial instance.

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).

all basic windows controls,wpf controls,silverlight application

here you will find all the information from basic.
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