BlogEngine.Net + Medium Trust + Surftown

Posted on November 24, 2010 07:06 by mystiqu

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>

Comments

November 29. 2010 04:02

Great tutorial!

Athena Sweden

August 11. 2011 08:22

I am very glad to see such information which I was searching for a long time!!This made very gladSmileThis site has given us an useful informationSmile

brentturkkkmay Brunei Darussalam

August 11. 2011 19:39

What you write in this blog is really good and very informative. I think it will help me in the futureLaughing Thanks for the good work

lavoonneevorce Bolivia

August 11. 2011 19:55

Hullo, simply become aware of your weblog through Google, and found that its really educative. Im gonna be careful for brussels. I’ll be grateful in the event you continue this in future. Numerous other folks will likely be benefited from your post. Thankx

tandrathurmond11 Belgium

August 11. 2011 22:36

Hello, nice day.. Your article is quite uplifting. I never believed that it was feasible to accomplish something like that until after I looked over your post. You certainly offered a great insight on exactly how this whole system operates. I will make sure to return for more advice. Keep it up!

mortgages for people with bad credit United States

November 28. 2011 19:13

I surprise to see that your site are related with this topic! I am seeking a blog design thats similar so thats the only reason Im asking. Thanks a lot!... Smile

OPC Factor Bulgaria

December 23. 2011 06:10

Thanks for such a wonderful Blog. I really get useful information about software support and various related aspects. Keep posting such good writings.

sex toys for men United Kingdom

January 2. 2012 21:38

Your blog article is very interesting and fanatic,at the same time the blog theme is unique and perfect,great job.To your success, one of the more impressive blogs I’ve seen. Thanks so much for keeping the internet classy for a change.

Houston Home Security United States

January 10. 2012 22:00

I Like your post.

sarees India

February 9. 2012 16:06

Thanks for the script.

fleshlight United Kingdom

February 24. 2012 08:30

It's great to see a blog of this quality. I learned a lot of new things and I'm looking forward to see more like this. Thank you.

cheap hotels in singapore Singapore

March 19. 2012 23:33

Outstanding post but I had been wanting to know should you could publish a litte more on this topic? I'd be really grateful for those who could elaborate slightly bit more. Appreciate it!

welcome United States

March 29. 2012 18:22

Nice Post...

Thesis Writing United States

April 4. 2012 23:55

Useful information ..I am very happy to read this article..thanks for giving us this useful information. Fantastic walk-through. I appreciate this post.

cheapest hotels in Singapore United States

April 22. 2012 08:27

Hi, nice post. I have been wondering about this topic, so thanks for sharing. I will certainly be subscribing to your blog.

singapore hotel deals Singapore

Add comment





  Country flag


Due to those nasty spammers I require all who want to comment to solve the recaptcha below.