Async is not working in large ASP.NET Application but in new application

Abhimanyu

I have an existing large ASP.NET (ASP.NET Web Forms + MVC support) Application and trying to implement async programming on project.

For that I created a completely new POC by selecting ASP.NET Application (again ASP.NET Web Forms + MVC support). My POC works great and correctly does async execution.

Now when I copy exact same code in existing large project, this behaves like synchronous. I already have latest .NET Framework updates in large application. Here is my Controller implementation which is supposed to upload file async:

[HttpPost]
[ValidateInput(false)]
public async Task<JsonResult> VideoUpload(string Id)
{
    for (int i = 0; i < Request.Files.Count; i++)
    {
        // :::::
        await Run(fileStream);
    }

    return Json(new { error = false, message = "File uploaded." });
}

public async Task Run(Stream fileStream)
{
    // :::::

    using (fileStream)
    {
        // A long running method call
        await fileUploadRequest.UploadAsync();
    }
}

[HttpGet]
public JsonResult GetUploadingStatus()
{
    // :::::
    return Json(new { statusMessage = statusMessage, totalSent = totalSent, totalSize = totalSize }, JsonRequestBehavior.AllowGet);
}

In above code GetUploadingStatus() is a GET method does quick job. This methods receives random (3-4 seconds interval) Ajax calls and returns uploading status.

When I debug this implementation in large project, I noticed GetUploadingStatus() returns every results (10-15 Json response) at a time just after fileUploadRequest.UploadAsync() ends. So I feel this behaves like synchronous in large project. Then why this works great in a clean project but not in large project?

Abhimanyu

To resolve this issue I just added [SessionState(SessionStateBehavior.Disabled)] with the controller which you can see below:

[SessionState(SessionStateBehavior.Disabled)]
public class UploadController : Controller
{
    [HttpPost]
    [ValidateInput(false)]
    public async Task<JsonResult> VideoUpload(string Id)
    {
        for (int i = 0; i < Request.Files.Count; i++)
        {
            // :::::
            await Run(fileStream);
        }

        return Json(new { error = false, message = "File uploaded." });
    }

    public async Task Run(Stream fileStream)
    {
        // :::::

        using (fileStream)
        {
            // A long running method call
            await fileUploadRequest.UploadAsync();
        }
    }

    [HttpGet]
    public JsonResult GetUploadingStatus()
    {
        // :::::
        return Json(new { statusMessage = statusMessage, totalSent = totalSent, totalSize = totalSize }, JsonRequestBehavior.AllowGet);
    }
}

Using this annotation may open some security breaches so verify it yourself before you annotate your controller.

Hope you find this useful.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Async is not working in large ASP.NET Application but in new application

From Dev

Why is async/await not working in my ASP.net 5 Console Application?

From Dev

ASP.NET Application not working on iPad

From Dev

Nested UnitOfWork is not working in Asp.net application

From Dev

Migrated ASP.NET application to new server

From Dev

How async / await can help in ASP.Net application?

From Dev

async/await not working in console application

From Dev

Button OnClick event not working in ASP.NET Web Form Application

From Dev

simple jQuery autocomplete example not working in ASP.NET Application

From Dev

ASP.NET MVC 2.0 application not working on server

From Dev

.subscribe is not working in my ASP.NET MVC application

From Dev

Asp.Net Application was not working when we deployed in IIS 8.0

From Dev

Angular 2 application not working in an ASP.NET 5 Environment

From Dev

ASP.NET Core 2.0 webapi application not working on Ubuntu 16.04

From Dev

Asp.net MVC application cannot be hosted and working properly

From Dev

Configuration error in ASP.NET application when deploying to new server

From Dev

Error when adding new ASP.Net Web Application

From Dev

.NET 4.0 Application Stopped working

From Dev

New Relic for local .NET application

From Dev

ASP.NET MVC Application on Ajax request with Kendo Chart with large datasource?

From Dev

Uploading a large file (up to 100gb) through ASP.NET application

From Dev

ASP.NET Forms Application

From Dev

Singleton in Asp.NET application

From Dev

Application Localization in asp.net

From Dev

Our ASP.NET core RC1 application stopped working and then started working again

From Dev

How to call some async code in an ASP.NET application_start

From Dev

UI thread is being blocked when using async/await with Task in ASP.NET web application

From Dev

async and await not working in asp.net MVC

From Dev

use Application variable in asp to asp.net

Related Related

  1. 1

    Async is not working in large ASP.NET Application but in new application

  2. 2

    Why is async/await not working in my ASP.net 5 Console Application?

  3. 3

    ASP.NET Application not working on iPad

  4. 4

    Nested UnitOfWork is not working in Asp.net application

  5. 5

    Migrated ASP.NET application to new server

  6. 6

    How async / await can help in ASP.Net application?

  7. 7

    async/await not working in console application

  8. 8

    Button OnClick event not working in ASP.NET Web Form Application

  9. 9

    simple jQuery autocomplete example not working in ASP.NET Application

  10. 10

    ASP.NET MVC 2.0 application not working on server

  11. 11

    .subscribe is not working in my ASP.NET MVC application

  12. 12

    Asp.Net Application was not working when we deployed in IIS 8.0

  13. 13

    Angular 2 application not working in an ASP.NET 5 Environment

  14. 14

    ASP.NET Core 2.0 webapi application not working on Ubuntu 16.04

  15. 15

    Asp.net MVC application cannot be hosted and working properly

  16. 16

    Configuration error in ASP.NET application when deploying to new server

  17. 17

    Error when adding new ASP.Net Web Application

  18. 18

    .NET 4.0 Application Stopped working

  19. 19

    New Relic for local .NET application

  20. 20

    ASP.NET MVC Application on Ajax request with Kendo Chart with large datasource?

  21. 21

    Uploading a large file (up to 100gb) through ASP.NET application

  22. 22

    ASP.NET Forms Application

  23. 23

    Singleton in Asp.NET application

  24. 24

    Application Localization in asp.net

  25. 25

    Our ASP.NET core RC1 application stopped working and then started working again

  26. 26

    How to call some async code in an ASP.NET application_start

  27. 27

    UI thread is being blocked when using async/await with Task in ASP.NET web application

  28. 28

    async and await not working in asp.net MVC

  29. 29

    use Application variable in asp to asp.net

HotTag

Archive