0

I am using ASP.NET Web Api with basic authentication.

My problem is that multiple API calls are not handled concurrently.

Let's say we call this simple method multiple times from a single machine with the same user credentials. If you run it 5 times in one second, the overall processing time will be 25 seconds instead of 5.

    [System.Web.Http.HttpGet]
    [System.Web.Http.Authorize(Roles = @"domain\group")]
    public string Test()
    {
        var startTime = DateTime.Now;
        System.Threading.Thread.Sleep(5000);
        var endTime = DateTime.Now;
        return $"{startTime} {endTime}";
    }

The answers to this question didn't help me:

I think it is because of the basic authentication.

I also tried changing the test method to async like this:

    [System.Web.Http.HttpGet]
    [System.Web.Http.Authorize(Roles = @"domain\group")]
    public async Task<string> Test()
    {
        var startTime = DateTime.Now;
        await Task.Run(() => {
            System.Threading.Thread.Sleep(5000);
        });
        var endTime = DateTime.Now;
        return $"{startTime} {endTime}";
    }

I also tried coloring the ApiController with [SessionState(SessionStateBehavior.ReadOnly)].

How can I achieve concurrent calls? Or should I change authentication to something else (must be connected to AD groups!)?

5
  • "Answers to Why is this web api controller not concurrent? doesn't seem to help me" - why not? Did you disable sessions? Commented May 3, 2018 at 6:54
  • My problem is that API calls are not concurrent. How did you come to that conclusion? Where is the API being called from? Commented May 3, 2018 at 6:56
  • @CodeCaster - I added to my web.config <sessionState mode="Off"/> without success. Commented May 3, 2018 at 7:14
  • @mjwills API is called from local browser. If I call 2 requests at once I see, that startTime of 2nd request = endTime of 1st. On the other hand if I call one reqest from mozilla and 1 from chrome at once, they are processed concurrently. Commented May 3, 2018 at 7:16
  • 1
    Could you perhaps be running into stackoverflow.com/questions/985431/… ? How are you doing the local requests? Through AJAX? Something else? Commented May 3, 2018 at 8:21

1 Answer 1

0

@mjwills pointed me to the right direction. Code is perfectly OK. Problem was running concurrent requests from Chrome. When I wrote simple C# test application everything worked as expected.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.