Skip to content

The Dummy Programmer

Stories of daily programming

  • Home
  • The Dummy Programmer Robot
    • Overview
    • Version history & downloads
    • Tutorials
      • TDP Robot – The basics
      • A simple SQL Server backup solution
      • A simple SQL Server backup solution – A next step
  • My other dummy projects
  • Games
    • Space Y: An Asteroids clone
  • Services
    • What’s my user agent
    • What’s my IP address
  • About
  • Toggle search form

Configure access permission to a folder for an IIS Application pool

Posted on September 24, 2019September 24, 2019 By

Suppose you are developing an ASP.NET application and you have to configure write permissions to a certain folder, maybe because you use it as temporary folder to write some data.

You don’t want to assign “Everyone – Full control” to the folder because you want to be the most restrictive possibile.

Following I’m explaining to you step by step how you can do this…

In IIS 7.5 and greater, you have to assign permissions to the user which runs your application pool.

Usually, when you create a web application in IIS, IIS also automatically creates a new application pool with the same name.

As you can see in the sample below, I created a new application named “TestApp”.

IIS Application Example

Now click on “Application Pools” and you will see an application pool with the same name:

IIS Application Pool

 

By default, an application pool runs under the Identity “ApplicationPoolIdentity”, as you can see in the “Identity” column.

Now create a new folder under “C:” named “TempFolder”.

TempFolder under C:\

 

Select the folder, click the right mouse button, click on “Properties” and then click on the “Security” tab.

First of all I want to remove all the default permissions, except for the Administrators group and my current logged user, which of course is an administrator too. To do this, click on the button “Advanced”, and click on the button “Disable inheritance”.

Advanced Security

Then in the tab “Security” remove all the gruop and users, except the group “Administrators”.

Only administrators

I created an ASP.NET page that opens and writes a file in the folder with the newly configured permissions.

ASP.NET Page

This is the code of the click “Event” of the “Write file” button.

protected void Button1_Click(object sender, EventArgs e)
{
   StreamWriter SW = new StreamWriter(@"C:\TempFolder\MyFile.txt");
   SW.Write("This is a test row!");
   SW.Close();
}

Trying to click the button, you will get an access denied error:

Access denied

To solve the problem, go back to the permission window of the folder and click the “Add…” button:

Add Permissions

You will see the following window:

Select users or groups

In the “Enter the object names to select” insert the string “IIS AppPool\TestApp” and click “Check names”.

Note that “TestApp” is the name of the application pool under which the web application run. This name will be different in your case.

Select users or groups

Now press “OK” to close the window. You will see a new user “TestApp” in the “Group or user names” list. Be sure to check the permission “Full control” – “Allow”, then press “OK”.

TestApp added

After this, if you take again the test page and click on the “Write file” button, the file will be correctly created!

Hope this helps!

Bye bye!!

 

 

ASP.NET, ASP.NET MVC

Post navigation

Previous Post: How to know who is blocking a query in Sql Server
Next Post: Sql Server: apply an aggregate function to fields values in a row

Related Posts

Telerik RadGrid rendering problems with IE11 in compatibility mode ASP.NET
HTTP 500 – Internal server error in an ASP.NET application ASP.NET
Put an ASP.NET website under maintenance ASP.NET
ASP.NET MVC5 Security Exception on Aruba provider ASP.NET MVC
NPOI and Excel found unreadable content in ‘[filename].xls’ ASP.NET
System.Net.Sockets.SocketException (0x80004005): No such host is known ASP.NET

Search

Related posts

  • Create a folder starting with dot in Windows
  • Quickly open the startup folder in Windows 10
  • Failed to decode downloaded font: (your web application…
  • Run an old Apache ASP web application in Ubuntu 20.04

Categories

  • .NET 6 (1)
  • AJAX (1)
  • Android (2)
  • Apache (4)
  • ASP.NET (9)
  • ASP.NET MVC (3)
  • Avalonia UI (1)
  • BCP (1)
  • Bitlocker (2)
  • C# (14)
  • CentOS (4)
  • ClosedXML (1)
  • CLR (1)
  • DNS (1)
  • Encryption (3)
  • Excel (2)
  • FuelPHP (3)
  • Games (2)
  • Google Chrome (1)
  • GSuite (1)
  • HTML (1)
  • Imagick (2)
  • Javascript (1)
  • Kindle (1)
  • LAMP (3)
  • Linux (6)
  • MariaDB (2)
  • Mathematics (2)
  • MySql (4)
  • NPOI (1)
  • Office 365 (1)
  • Perl (1)
  • PHP (6)
  • Programming (1)
  • Remote desktop (1)
  • SFTP (2)
  • Sockets (3)
  • Sql Server (18)
  • Sql Server 2016 (14)
  • Sql Server 2019 (1)
  • SSL (2)
  • Task scheduler (1)
  • Telerik ASP.NET AJAX (2)
  • The Dummy Programmer Chat (2)
  • The Dummy Programmer Robot (6)
  • Threading (5)
  • Tools (1)
  • TPL (3)
  • TypeScript (3)
  • Ubuntu (4)
  • Virtualization software (3)
  • Visual Studio (1)
  • Visual Studio Code (2)
  • Web fonts (1)
  • Web programming (6)
  • Windows (12)
  • Windows 10 (15)
  • Windows Forms (1)
  • Windows Server (6)

Copyright © 2023 The Dummy Programmer | Privacy Policy | Terms of use |

Powered by PressBook Masonry Dark