python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
The asynchronous action method 'Login' returns a Task

Asynchronous Action Method Returns a Task, which cannot be Executed Synchronously

The error as given below.

System.InvalidOperationException' occurred in System.Web.Mvc.dll but was not handled in user code.

Additional information: The asynchronous action method 'Login' returns a Task, which cannot be executed synchronously.


The solution for the above error as given below in details.


Firstly, I have changed the application running process [5228] iisexpress.exe to [3840] ieexpoler.exe and run the application, error is resolved.


And the Second step below code changed.


var rc = new RequestContext( new HttpContextWrapper(Context), routeData);
controller.Execute(rc);

Replace above code by given below code.

((IController)controller).Execute(new RequestContext(new HttpContextWrapper(HttpContext.Current), routeData));

And In the 3rd Steps changed the name of login action

        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            //....... 
            // If we got this far, something failed, redisplay form
            return View(model);
        }

Replace the above action name Login to LoginUser.

        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> LoginUser(LoginViewModel model, string returnUrl)
        {
            //...... 
            // If we got this far, something failed, redisplay form
            return View(model);
        }

Please see below video for how to changed the application process.





ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions