Skip to main content

Setting folder permissions using Web Deploy

Learn how to set folder permissions to your ASP.NET projects when using Web Deploy

Posted in Configuration, Web Deploy, Code snippets, Tutorials, ASP.NET

I was running into a very odd problem recently: I couldn't upload files to my website because of an error saying that I didn’t have permission to write files into the App_Data folder. I’ve decided to look into it and I realized that it began since I started using Web Deploy.

For those unfamiliar with Web Deploy I will tell you something: This is the best deployment tool for ASP.NET websites so far. It checks the files before you send to the server so it will send only those which had some change, publish entire databases and even pre-populate the tables.

The problem is that Web Deploy resets all folder permissions, which basically broke my file upload. And since ELMAH couldn't log the errors I spent some time thinking that my website was running flawlessly perfect. Silly me...

The solution I found was to create a .targets file in order to set the permissions during the deployment time. Let’s see how to do it:

  1. Create a .wpp.targets file in the root of your web project. You may not find this file in your File -> New window. In that case just create a normal Text File, change the extension and add XML content in it, as you can see in the gist below:
  2. Set the permissions to the folders you want. In my case, the App_Data was just enough but you can add other folders as well (lines 15 to 29).
  3. Deploy through Web Deploy. A very simple explanation of this step: When you deploy the MSBuild will run, pass through the .targets file you’ve created and set the permissions to the folders you’ve defined.

You might keep some things in mind:

  • Visual Studio caches the .targets files, which means that you will have to restart Visual Studio every time you want to make changes and see the effects when you are building the deployment package.
  • The package will not be rebuild unless you actually make changes in the .targets file.
  • Remember to always use Clean Solution in case you want to rebuild the deployment package.

For more information visit the Sayed Ibrahim Hashimi’s website.

Did you like the article?

You can subscribe and get them as soon they are online, share using the buttons bellow or leave a comment.

And you also can share using your favorite social network:

Using web.config to make your ASP.NET project accept LESS CSS

Learn how to solve the 404 error you get when you try to run an ASP.NET project with .less files

Posted in Configuration, Tutorials, IIS, ASP.NET

Every ASP.NET developer must love the web.config file. Seriously, I will write about it some day. :-)

Some time ago, we have faced a very interesting problem in one of our ASP.NET projects. We have decided to use LESS CSS in order to optimize the front-end development and speed up the things a bit. While we knew that we should compile the LESS files before throw it to production we were facing an error during the development phase:

HTTP Error 404.3 - Not Found

The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

The reason: IIS doesn’t support .less files by default.

By this time we have 2 solutions: The first one is to call the responsible for the webserver and ask him to add a new MIME type into the IIS. But thanks to the .NET architecture we don't need to do that. All we need to do is to add some extra lines to your web.config, inside , as seen bellow:

<system.webServer>
  <staticContent>
    <remove fileExtension=".less" />
    <mimeMap fileExtension=".less" mimeType="text/css" />
  staticContent>
system.webServer>

As you saw it’s simple, clear and useful. Keep in mind that you can use the same method to solve the problem with other non-supported files such as webfonts (.eot, .woof), videos (.mp4, .ogg, .m4v), images (.svg, .svgx) and so on (as Mads Kristensen wrote).

Did you like the article?

You can subscribe and get them as soon they are online, share using the buttons bellow or leave a comment.

And you also can share using your favorite social network: