Click here to Skip to main content
15,896,348 members
Home / Discussions / C#
   

C#

 
AnswerRe: Static method in a class with a protected contructor confusion Pin
Guffa18-Aug-08 2:54
Guffa18-Aug-08 2:54 
GeneralRe: Static method in a class with a protected contructor confusion Pin
Brendan Vogt18-Aug-08 20:26
Brendan Vogt18-Aug-08 20:26 
QuestionBrowse DataReader results in DataGridView Pin
AndrusM18-Aug-08 0:24
AndrusM18-Aug-08 0:24 
AnswerRe: Browse DataReader results in DataGridView Pin
bhadeliaimran18-Aug-08 1:01
bhadeliaimran18-Aug-08 1:01 
GeneralRe: Browse DataReader results in DataGridView Pin
AndrusM18-Aug-08 1:14
AndrusM18-Aug-08 1:14 
QuestionHttpWebRequest Pin
Aleemulhaq17-Aug-08 23:14
Aleemulhaq17-Aug-08 23:14 
GeneralRe: HttpWebRequest Pin
Pete O'Hanlon17-Aug-08 23:28
mvePete O'Hanlon17-Aug-08 23:28 
QuestionImpersonation with IPCChannel Pin
alex120517-Aug-08 22:53
alex120517-Aug-08 22:53 
Hi,

I am trying to connect to IPCChannel using an impersonated user and had encountered an Access Denied exception. Have anyone encountered this? Please help.

Please see some code snippets below:

Server:

BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

System.Collections.IDictionary props = new System.Collections.Hashtable();

props["portName"] = "TestRemoteObject";
props["name"] = "TestRemoteObject";

props["authorizedGroup"] = "Everyone";

props["impersonate"] = true;
props["secure"] = true;

serverChannel = new IpcServerChannel(props, serverProvider);

ChannelServices.RegisterChannel(serverChannel, true);

RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "TestRemoteObject", WellKnownObjectMode.Singleton);

Client:

BinaryClientFormatterSinkProvider clientSink = new BinaryClientFormatterSinkProvider();

System.Collections.IDictionary clientProps = new System.Collections.Hashtable();

clientProps["secure"] = true;
clientProps["tokenImpersonationLevel"] = TokenImpersonationLevel.Delegation;

IpcClientChannel clientChannel = new IpcClientChannel(clientProps, clientSink);

ChannelServices.RegisterChannel(clientChannel, true);

// Impersonate user to use Administrator
IntPtr token;
bool result = LogonUser(
"Administrator", "MyMachine",
"MyPassword",
LogonTypes.Network,
LogonProviders.Default,
out token);

if (result)
{
WindowsIdentity identity = new WindowsIdentity(token);

using (WindowsImpersonationContext imp = identity.Impersonate())
{
try
{
RemoteObject remote = (RemoteObject)Activator.GetObject(typeof(RemoteObject), "ipc://TestRemoteObject/TestRemoteObject");

message = remote.Echo("Test");
}
catch (Exception exc)
{
message = exc.ToString();
}

imp.Undo();

}

MessageBox.Show(message);

CloseHandle(token);
}

Error Message:

System.Runtime.Remoting.RemotingException: Failed to connect to an IPC Port: Access is denied.

Server stack trace:

at System.Runtime.Remoting.Channels.Ipc.IpcPort.Connect(String portName, Boolean secure, TokenImpersonationLevel impersonationLevel, Int32 timeout)

at System.Runtime.Remoting.Channels.Ipc.ConnectionCache.GetConnection(String portName, Boolean secure, TokenImpersonationLevel level, Int32 timeout)

at System.Runtime.Remoting.Channels.Ipc.IpcClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)

at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)



If I tried to run client application using the administrator account, then connect without impersonating, it works fine. However, if I am doing impersonation it fails. Hope to get some help. Thanks in advance. Smile | :)

SDE

AnswerRe: Impersonation with IPCChannel Pin
leppie18-Aug-08 2:08
leppie18-Aug-08 2:08 
GeneralRe: Impersonation with IPCChannel Pin
alex120518-Aug-08 15:52
alex120518-Aug-08 15:52 
QuestionHow to solve the Guid.NewGuid() problem Pin
Exelioindia17-Aug-08 22:49
Exelioindia17-Aug-08 22:49 
AnswerRe: How to solve the Guid.NewGuid() problem Pin
N a v a n e e t h17-Aug-08 23:08
N a v a n e e t h17-Aug-08 23:08 
GeneralRe: How to solve the Guid.NewGuid() problem Pin
Exelioindia17-Aug-08 23:10
Exelioindia17-Aug-08 23:10 
AnswerRe: How to solve the Guid.NewGuid() problem Pin
Pete O'Hanlon17-Aug-08 23:26
mvePete O'Hanlon17-Aug-08 23:26 
Questionpublished folder does not contain any files Pin
dsaikrishna17-Aug-08 22:48
dsaikrishna17-Aug-08 22:48 
AnswerRe: published folder does not contain any files Pin
AhsanS17-Aug-08 23:24
AhsanS17-Aug-08 23:24 
QuestionWhat happend Pin
Pedram Behroozi17-Aug-08 22:10
Pedram Behroozi17-Aug-08 22:10 
AnswerRe: What happend Pin
CPallini17-Aug-08 22:36
mveCPallini17-Aug-08 22:36 
GeneralRe: What happend Pin
Pedram Behroozi18-Aug-08 6:37
Pedram Behroozi18-Aug-08 6:37 
Questionadding a checkbox to a datagridview Pin
laziale17-Aug-08 21:17
laziale17-Aug-08 21:17 
AnswerRe: adding a checkbox to a datagridview Pin
dan!sh 17-Aug-08 22:19
professional dan!sh 17-Aug-08 22:19 
AnswerRe: adding a checkbox to a datagridview Pin
Mogaambo17-Aug-08 22:20
Mogaambo17-Aug-08 22:20 
GeneralRe: adding a checkbox to a datagridview Pin
laziale17-Aug-08 22:27
laziale17-Aug-08 22:27 
GeneralRe: adding a checkbox to a datagridview Pin
Mogaambo17-Aug-08 22:34
Mogaambo17-Aug-08 22:34 
GeneralRe: adding a checkbox to a datagridview Pin
laziale17-Aug-08 22:39
laziale17-Aug-08 22:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.