I am coding a MVC 5 internet application, and have a question about being redirected to a logon page after seeding a database.
Here is my controller code:
public class SetupController : Controller
{
[AllowAnonymous]
public async Task<ActionResult> SetupApplication()
{
Database.SetInitializer<ApplicationDbContext>(new ApplicationDbInitializer());
ApplicationDbContext applicationDbContext = new ApplicationDbContext();
applicationDbContext.Database.Initialize(true);
return RedirectToAction("Index", "Home");
}
}
In the seed
method, I am adding some objects to a different DbContext
class, and for some reason, the logon
page is being displayed afterwards. The ApplicationDbContext
is for the IdentityStore
. If I do not add any objects to the different DbContext
class, the logon
page is not shown.
When the logon
page is displayed, the following exception
is logged:
System.InvalidOperationException: An asynchronous module or handler completed while an asynchronous operation was still pending.
The exception
occurs at:
Account\Login
If I comment out all of the code in the above method, except the RedirectToAction
, the Index
ActionResult
is executed, and I am not required to logon
. So I can browse to the Index
ActionResult
and I do not need to enter in any logon
information. The exception
does not occur with the code commented out.
Here is the Index
ActionResult
:
[AllowAnonymous]
public async Task<ActionResult> Index()
{
return View();
}
Why would be the reason for this? What coding concept is occuring here? I do not believe I need to show code, but if needed, I will.
Thanks in advance.