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 6892375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:31:38+00:00 2026-05-27T06:31:38+00:00

// test.ashx public class test : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType

  • 0
// test.ashx
public class test : IHttpHandler {

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        try
        {
            File.WriteAllText(@"D:\inetpub\site.net\www\gs\data\test.txt", "Test");
            Thread t = new Thread(write);
            t.Start();
            context.Response.Write("OK");
        }
        catch (Exception ex) 
        {
            context.Response.Write(ex.Message);
        }
    }

    private void write()
    {
        try
        {
           File.WriteAllText(@"D:\inetpub\site.net\www\gs\data\test2.txt", "Test2");
        }
        catch (Exception ex)
        {
            LogManager.Instance.Write(ex.Message);
        }
    }

    public bool IsReusable {
        get {
            return false;
        }
    }
}

I have a simple ashx file that writes two text files to the disk of server. One is written directly and another is written in a separate thread.

The problem is, File.WriteAllText method which is executed in separate thread causes an Access Denied exception. In other words “test.txt” is written but “test2.txt” causes Access Denied exception.

Is there a way to give a thread Read/Write rights of main Session thread?

  • 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-27T06:31:39+00:00Added an answer on May 27, 2026 at 6:31 am

    The thread that executes your ASP.NET request is one of the I/O threads or one of the workerThreads in the ASP.NET worker process (aspnet_wp.exe). These threads are all Multi-Threaded Apartment (MTA) threads. If you programmatically impersonate an account in your .aspx or .asmx code, or if you impersonate by using in Web.config or Machine.config, then the impersonation token is held on this MTA thread. If you then make a call into a single-threaded or an apartment-threaded COM component, that component is accessed by an entirely different thread, which is the single thread in its Single-Threaded Apartment (STA). Because this STA thread does not have an impersonation token of its own, and the impersonation token of the MTA thread is not passed to the STA thread, the STA thread then executes under the process identity.

    In order to solve this problem, take a look here :
    http://support.microsoft.com/kb/325791#top

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

Sidebar

Related Questions

test.txt is a \n split text file: f = open('test.txt','r') f.read(256) But while read
test RandomNumberGenerator rng; cout << rng() << endl; header class RandomNumberGenerator { public: unsigned
@Test public void testB() throws ScriptException, NoSuchMethodException { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine
So I have a method that implements IHttpHandler.ProcessRequest. It accepts an HttpContext parameter. This
test@SERVER:~/source/dropbox/.dropbox-dist$ ./dropbox.py Traceback (most recent call last): File ./dropbox.py, line 39, in <module> import
test.html: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd> <html xmlns=http://www.w3.org/1999/xhtml xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd xml:lang=en> <head><title>Test</title></head>
I'm trying to test another application by requesting many file downloads. So, I started
Test case: <!DOCTYPE html> <html> <head> <meta charset=UTF-8 /> <script type=text/javascript src=/cufon.js></script> <script type=text/javascript
#test is the selector for id=test .test is the selector for class=test but how
test.php <?php $filec = fopen('test.txt','w'); $arr = file('test.txt'); foreach ($arr as $key => $value)

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.