Patrick
Patrick

Reputation: 2790

asp.net impersonate from server in domain to server outside domain

Im using this code http://platinumdogs.wordpress.com/2008/10/30/net-c-impersonation-with-network-credentials/#comment-770 to connect from a machine in the domain to a machine outside the domain.

The web-application I wrote connects from a webserver to a fileshare to dropoff files.

My problem is that I cant get the right credentials in one situation. In both scenarios described below I use the same backend dll.

I have 2 aplications running this code. 1 with both machines outside the domain and one with the webserver in the domain and the data server outside the domain. The code that is running on the server that performs the request from a non-domain webserver server to the non-domain data server is working. The code that on the domain web server and is requesting the non domain data server is not working.

To test further we took the domain server out of the domain and without further changes the code was working again. So it looks like there is something I have to change (a setting maybe) to let this work. Does anyone what I need to do to fix this?

@----------- Extra info for questions below:

It is a static username passwor, specified in the config file. The account is not a domain account and the same account as used on the other server.

    Request information: 
    Request URL: http://XXX.XXX.XXX.XXX/nl-nl/Attachment/GetAllFileNames 
    Request path: /nl-nl/Attachment/GetAllFileNames 
    User host address: XXX.XXX.XXX.XXX 
    User:  
    Is authenticated: False 
    Authentication Type:  
    Thread account name: NT AUTHORITY\NETWORK SERVICE 

    Thread information: 
    Thread ID: 1 
    Thread account name: NT AUTHORITY\NETWORK SERVICE 
    Is impersonating: False 
    Stack trace:    at System.Web.Mvc.ViewResult.FindView(ControllerContext context)
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
     at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
     at System.Web.Mvc.Controller.ExecuteCore()
     at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
     at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
     at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
   at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
   at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Upvotes: 2

Views: 689

Answers (1)

Patrick
Patrick

Reputation: 2790

I found the problem.

When comming from a domain server I have to use logon_type_new_credentials (9) instead of interactive (2).

Upvotes: 2

Related Questions