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

  • SEARCH
  • Home
  • 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 9190969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:34:34+00:00 2026-06-17T20:34:34+00:00

I want to be able to load a user from a cloud database on

  • 0

I want to be able to load a user from a cloud database on each request and have that available on the request in a controller using asp.net mvc. The problem is the current framework does not support doing async operations from action filters. So OnActionExecuting, OnAuthorization methods do not allow me to do this.. for example I have the following code which DOES NOT work (so don’t try it).. You get an exception : “An asynchronous module or handler completed while an asynchronous operation was still pending.”

protected async override void OnAuthorization(AuthorizationContext filterContext)
{
  var user = filterContext.HttpContext.User;
  if (!user.Identity.IsAuthenticated)
  {
    HandleUnauthorizedRequest(filterContext);
    return;
  }

  using (var session = MvcApplication.DocumentStore.OpenAsyncSession())
  {
    User currentUser = await session.LoadAsync<User>(user.Identity.Name);
    if (currentUser == null)
    {
      HandleUnauthorizedRequest(filterContext);
      return;
    }

    filterContext.HttpContext.Items["User"] = currentUser;
  }
}

So is there any other way of being able to do this? I notice there is a begin execute method in the base Controller:

protected override IAsyncResult BeginExecute(RequestContext requestContext, AsyncCallback callback, object state)
{
  return base.BeginExecute(requestContext, callback, state);
}

Could I do it there possibly?

  • 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-17T20:34:35+00:00Added an answer on June 17, 2026 at 8:34 pm

    The question is three months old so I guess you’ve managed to work around this. Anyway, I’ll add my solution here, as I had to do something similar.

    I used the ToAsync method from the ParallelExtensionsExtras library. This is my class:

    public class AsyncControllerBase : Controller
    {
        protected override IAsyncResult BeginExecute(System.Web.Routing.RequestContext requestContext, AsyncCallback callback, object state)
        {
            return ExecuteCoreAsync(requestContext, state).ToAsync(callback, state);
        }
    
        protected override void EndExecute(IAsyncResult asyncResult)
        {
            IAsyncResult baseAsyncResult = ((Task<IAsyncResult>)asyncResult).Result;
            base.EndExecute(baseAsyncResult);
        }
    
        protected virtual async Task<IAsyncResult> ExecuteCoreAsync(System.Web.Routing.RequestContext requestContext, object state)
        {
            await DoStuffHereOrInDerivedClassAsync();
    
            var baseBeginExecuteCompletion = new TaskCompletionSource<IAsyncResult>();
    
            AsyncCallback callback = ar =>
            {
                baseBeginExecuteCompletion.SetResult(ar);
            };
    
            // OnActionExecuting will be called at this point
            var baseAsyncResult = base.BeginExecute(requestContext, callback, state);
    
            await baseBeginExecuteCompletion.Task;
    
            return baseAsyncResult;
        }
    
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
        }
    }
    

    See also this documentation from Microsoft on converting between Task and IAsyncResult.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iframe that loads by user request so its not available on
I have an ASP.NET page that I want to be able to generate and
I want to make the user of the app I'm developing, able to load
I want to be able to take an image that i have already captured
in my js file i want to be able to load a splash screen
I want to be able to display child rows upon load. Right now I
I'm using LaTeX and BibTeX for an article, and I want to able to
I want to be able to save and load documents, so I'm trying to
In my app based on spotify, I don't want to load user specific playlist,
I have a python web server (cherrypy), and I want the user to be

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.