Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 366399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:37:44+00:00 2026-05-12T13:37:44+00:00

I have a MVC web application on an intranet and want to be able

  • 0

I have a MVC web application on an intranet and want to be able to create files on our FTP server to send to outside partners.

The code for impersonation uses the WindowsImpersonationContext.

System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext = ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();

StreamWriter sw = System.IO.File.CreateText("PathOnFTPServer");
sw.Write("data");

impersonationContext.Undo();

Here’s what’s happening and the reason for my question:

Pre Impersonation

User.Identity.Name: [my windows credentials]

System.Security.Principal.WindowsIdentity.GetCurrent().Name: NT AUTHORITY\NETWORK SERVICE

Post Impersonation

User.Identity: [my windows credentials]

GetCurrent.Name: [my windows credentials]

Impersonate Undo

User.Identity: [my windows credentials]

GetCurrent.Name: NT AUTHORITY\NETWORK SERVICE

So, before I impersonate, the current user is the System Account but after impersonation, it is using my windows domain account which has permission to create text files on the FTP server. The code works locally using the visual studio web server but not when I deploy it on IIS on our test server.

I’m getting an access denied error. What would be the reason for the error when the correct user is being impersonated?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:37:45+00:00Added an answer on May 12, 2026 at 1:37 pm

    Impersonation allows machine to machine impersonation, so the client browser and the server are on the same page when it comes to the impersonation. When you then attempt to access the network share, the computer doesn’t trust the impersonated credentials.

    You need to enable delegation for the IIS machine in Active Directory. Go to Active Directory Users and Computers, find the computer, click properties, and ‘Trust computer for delegation’. (You might need to restart IIS for this to work, I don’t remember).

    There is way more theory than this that I don’t fully understand, but this should work. Whether it is right or not someone else could comment on!

    Also, the reason it works on your development machine is that the development server runs as the developer, not (Local)\Network Service.


    A decent link:

    http://msdn.microsoft.com/en-us/library/cc949004.aspx

    What is the difference between impersonation and delegation?

    Impersonation flows the original caller’s identity to back-end resources on the same computer. Delegation flows the original caller’s identity to back-end resources on computers other than the computer running the service.

    For example, if a service is running within IIS without impersonation, the service will access resources using the ASP.NET account in IIS 5.0, or the Network Service account in IIS 6.0. With impersonation, if the client is connecting using the original caller’s account, the service will access resources such as a SQL Server database on the same machine using the original caller’s account instead of the system ASP.NET account. Delegation is similar except that the SQL Server database could be on a different machine that is remote to the service.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have asp.net mvc 4 web application project on my server in IIS Directory.
I have a Asp.net MVC web application, containing mostly text. I want to put
I have created blank Asp.Net-MVC 3 web application and want to write my own
We've recently developed an internal web application for our intranet on top Microsoft's MVC
I have a MVC web application (Ruby, Rack, Apache) and I want it to
So I have our MVC web application up and running and we'd like to
We have written Web application using ASP.NET MVC, which will be hosted in our
I have enabled form authentication in my ASP.NET MVC web application. I want to
I have ASP.NET MVC Beta on our web server running a few apps. My
I have an ASP.NET MVC Web Application that interacts with a SQL Server 2008

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.