If you are using BlogEngine.Net on a site hosted by Surftown you have probably noticed that you get prompted with a credentials popup every now and then. This is because Surftown are running their applications in Medium Trust, which means you (NETWORK_SERVICE to be exact) don´t have any write access to the App_Data folder. Turn off “custom errors” on web.config and you´ll see a permission denied error.
Since the application is running under the NETWORK_SERVICE user we must give that user write privileges to the App_Data folder and all subfolders and files. Luckaly, surftown are nice enough to allow this and has also provided a script you can run to give the NETWORK_SERVICE user write access to any folder you wish. However, for security reasons you should keep the write access privileges to a minimum!
You can find the script here.
For all of you that don´t speak swedish – here comes a translation.
1. Create an aspx file and name it to change.aspx
2. Add the code below
3. Upload the file to a domain other than the domain where you keep your blog, e.g. create a temporary sub domain
4. Verify the ASP.NET version is set to 2.0 on the surftown control panel
5. Surf to the change.aspx page
6. You will be prompted by a credentials box. Supply your ftp credentials.
7. Done! Hopefully it worked and your application should run smoothly from now.
The Script
Download it here
1: <%@ Page Language="C#" %>
2:
3: <%@ Import Namespace="System.Security.AccessControl" %>
4: <%@ Import Namespace="System.Security.Principal" %>
5: <%@ Import Namespace="System.IO" %>
6:
7: <script runat="server">
8: protected void ChangeBT_Click(object sender, EventArgs e)
9: {
10: // Get path from TextBox
11: string path = PathTB.Text;
12:
13: // The account which should be granted access
14: NTAccount acc = new NTAccount(@"NT AUTHORITY\NETWORK SERVICE");
15:
16: // Rights which should be changed
17: FileSystemRights rightName = FileSystemRights.Modify;
18: AccessControlType right = AccessControlType.Allow;
19:
20: // Inherit to all subdirectories and files
21: InheritanceFlags iFlags = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;
22: PropagationFlags pFlags = PropagationFlags.InheritOnly;
23:
24: // Get current filesecurity object
25: DirectorySecurity security = Directory.GetAccessControl(path);
26:
27: // Create new rule
28: FileSystemAccessRule rule = new FileSystemAccessRule(acc, rightName, iFlags, pFlags, right);
29:
30: // Add new rule to the security object
31: security.AddAccessRule(rule);
32:
33: // Update file access control
34: Directory.SetAccessControl(path, security);
35:
36: UpdatedLB.Visible = true;
37: }
38: </script>
39:
40: <html>
41: <body>
42: <form id="Form1" runat="server">
43: <p>
44: Path: (d:\hshome\username\yourdomain\foldername)<br />
45: <asp:TextBox ID="PathTB" runat="server" Width="250px" />
46: </p>
47: <p>
48: <asp:Button ID="ChangeBT" runat="server" Text="Change Permissions" onclick="ChangeBT_Click" />
49: </p>
50: <p>
51: <asp:Label ID="UpdatedLB" runat="server" Text="Permissions changed!" Visible="False" />
52: </p>
53: </form>
54: </body>
55: </html>
11cc3677-2b45-403b-9657-7f7817fa3e76|0|.0