How to obtain client identity in remote server using HTTP channel  
Author Message
tanmos





PostPosted: .NET Remoting and Runtime Serialization, How to obtain client identity in remote server using HTTP channel Top

I am working on a remoting application where the windows form on the client side connects to the business component on a remote server for the processing. We are hosting the remote object in a console application and using singleton server activation for remoting. Now my remote server needs to obtain the client's user information to do some client-specific processing and I am trying to obtain the same with the following code in my remote host application:

string userName = System.Threading.Thread.CurrentPrincipal.Identity.Name;

This works fine and returns the 'domain/username' if I use TcpChannel for communication, but if I switch to HttpChannel for remoting, Thread.CurrentPrincipal.Identity.Name returns empty string. I tried using System.Web.HttpContext.Current.User.Identity.Name too but HttpContext.Current is returning null.

Any help or pointers to the solution will be of great help. Thanks in advance !!!



.NET Development29  
 
 
Vipul Modi - MSFT





PostPosted: .NET Remoting and Runtime Serialization, How to obtain client identity in remote server using HTTP channel Top

You need to host your server in IIS to get the client authentication with HTTP.

From http://msdn2.microsoft.com/en-us/library/36tfwzb0.aspx

You can require caller authentication for a remote service that uses the HttpChannel class and is hosted in IIS. In contrast to the procedure used for server-side authentication configuration when using the TcpChannel class, this is done using IIS and ASP.NET settings instead of using channel configuration properties. See the IIS documentation and ASP.NET Web Application Security for details on configuring IIS and ASP.NET for authentication.

- Vipul



 
 
tanmos





PostPosted: .NET Remoting and Runtime Serialization, How to obtain client identity in remote server using HTTP channel Top

Thanks Vipul. But there is a caveat. If I use IIS to host the remote service, users may not able to access the remote service using their windowsidentity due to authorization failure (unless I allow each and every user in the web.config, which is not quite feasible). On the other hand, if I enabale anonymous access, the HttpContext.User.Identity.Name will always come as blank (http://msdn2.microsoft.com/en-us/library/134ec8tc.aspx). So either way, I will not be able to get the user's windows identity (logon name). Any comments


 
 
Vipul Modi - MSFT





PostPosted: .NET Remoting and Runtime Serialization, How to obtain client identity in remote server using HTTP channel Top

Integrated windows authetication does not require you to specify the users in the Web.Config, can you provide more details about your scenario.

- Vipul



 
 
Vipul Modi - MSFT





PostPosted: .NET Remoting and Runtime Serialization, How to obtain client identity in remote server using HTTP channel Top

Make sure that you have configured the Impersonation. This is required to get the client identity.

http://msdn2.microsoft.com/en-us/library/xh507fc5.aspx

In your web.config enable impersonation.

<configuration>
<system.web>
<identity impersonate="true"/>
</system.web>
</configuration>

Use the following property to access the name of the impersonated user.

String username =
System.Security.Principal.WindowsIdentity.GetCurrent().Name;

Let me know if this works for you.

- Vipul



 
 
tanmos





PostPosted: .NET Remoting and Runtime Serialization, How to obtain client identity in remote server using HTTP channel Top

Thanks for all help. I have found an alternative solution in the form of CallContext. As I am using a console application to host the remote object, this is serving my purpose very well. I am setting the user name in CallContext in client side and getting the user name from CallContext in server. This should work fine in IIS host too.