简体   繁体   中英

Requests get other request value in ASHX Handler?

I had a job interview and I was asked the following:

Let's say 2 requests were sent at the exact same time to an ashx(handler).

First request: http://www.secretwordHandler.com/?SecretWord=ABRA

Second request: http://www.secretwordHandler.com/?SecretWord=KADABRA

This is the ashx:

public void ProcessRequest (HttpContext context) {

        Random rnd = new Random();
        int randomSleepTime = rnd.Next(1000, 10001);

        Thread.Sleep(randomSleepTime);

        string secretWord = HttpContext.Current.Request.QueryString["SecretWord"];

        Thread.Sleep(randomSleepTime);

        //What is the secret Word??
        Console.WriteLine(secretWord);

    }

Is it possible that the first request will get the result of the second request?

I wasn't sure about answer to it I must admit because the thread sleep I got confused...

It seems that HttpContext.Current is not thread safe, but it doesn't have to. It is explained in this article from Marcus van Houdt: Understanding the SynchronizationContext in ASP.NET

To answer your question: it should not be possible that the first request will get the result of the second request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM