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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:58:44+00:00 2026-06-07T19:58:44+00:00

I am using async and await in a controller. The following code works fine

  • 0

I am using async and await in a controller.

The following code works fine

[HttpPost]
[ValidateAntiForgeryToken]        
public async Task<ActionResult> Create(CompetitionViewModel viewModel)
{
        if (ModelState.IsValid)
        {

            User user = null;
            using (var facebookClient = new FacebookClient(viewModel.AccessToken))
            {
                var facebookUser = await facebookClient.Me();
                user = entityStorage.GetUser(facebookUser);
                FormsAuthentication.SetAuthCookie(user.FacebookId, true);
            }

However if I try and execute the same code in an extension method then the await never completes.

[HttpPost]
[ValidateAntiForgeryToken]        
public ActionResult Create(CompetitionViewModel viewModel)
{
    if (ModelState.IsValid)
    {
        var user = entityStorage.GetCurrentUser(viewModel.AccessToken).Result;

and

public static class Helpers
    {
        public async static Task<User> GetCurrentUser(this IEntityStorage entityStorage, string accessToken)
        {
            User user = null;
            using (var facebookClient = new FacebookClient(accessToken))
            {
                var facebookUser = await facebookClient.Me(); //STUCK HERE!!
                user = entityStorage.GetUser(facebookUser);
                FormsAuthentication.SetAuthCookie(user.FacebookId, true);
            }
            return user;
        }

I am using MVC4 and have <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> set in my web.config as per other threads suggestions.

Can anyone tell me why this is and how I can get it to work?

  • 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-06-07T19:58:45+00:00Added an answer on June 7, 2026 at 7:58 pm

    I have a blog post that covers this in detail.

    In short, you are causing a deadlock by calling Result. Instead, make your Create method async and use await to get the user.:

    [HttpPost]
    [ValidateAntiForgeryToken]        
    public async Task<ActionResult> Create(CompetitionViewModel viewModel)
    {
      if (ModelState.IsValid)
      {
        var user = await entityStorage.GetCurrentUser(viewModel.AccessToken);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following method: public async Task<MyObject> DoSomethingAsync() { // do some work await
Using latest CTP5 with async/await keywords, I wrote some code, which apparently cannot compile:
I have a NetworkStream which I read asynchronously (using async/await) await Task<int>.Factory.FromAsync((cb, state) =>
I'm trying to download strings from a HttpPost and I'm using the Async class
Using LINQ on collections, what is the difference between the following lines of code?
I am using async task for downloading an audio file and I am having
I have a public async Task Foo() method that I want to call from
2013 Edit: async and await now make this trivial! :-) I've got some code
What is the advantage of writing the following WCF service operation using Async CTP?
I'm using the code below to download this XML file : private async static

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.