UPDATE: I remove all of the async calls and made it completely synchronous and I am still experiencing this issue so it is not an issue with async.
So I have a LoginLayout in my layouts. Its not the main layout file. When a user logs in we determine some conditional values in the datababase and then redirect them accordingly to an intermediary page or directly to our dashboard.
If our user gets directed to the intermediary page first, and in this instance they click a submit button that posts to an action, then everything works as expected. But if we dont load the intermediary page and instead redirect to a different action which calls the same Logon function. They should go straight to the dashboard aka do not return a view instead return a RedirectToAction
, the same function breaks the layout of the Dashboard.
I can actually see MVC is rendering the main _layout file INSIDE the LoginLayout files @RenderBody()
method. and the URL does not change to /Dashboard which is also strange.
It is also worth noting that I have tried RedirectToAction
, RedirectToRoute
, Redirect all do the exact same thing. Also once the garbled page loads if I manually navigate to /Dashboard it renders correctly.
Here is the code
//In my Login controller PostLogin method
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogonPost(LoginModel model)
{
//validate login and if all good then
return RedirectToAction("Index", "Intermediary");
}
//Intermediary Controller this one does not work if called page is loaded wierd as described
public async Task<ActionResult> Index()
{
await Task.Run(() =>
{
//grab database stuff in here set session vars etc
});
return await PostLogonConnecting();
}
This one gets called as a post from the page when they click a button and works fine
public async Task<ActionResult> PostCompany(CompaniesListModel model)
{
//do db stuff
return await PostLogonConnecting();
}
This PostLogonConnecting is in my base class so it can be called from multiple controllers.
public async Task<RedirectToActionResult> PostLogonConnecting()
{
await Task.Run(() =>
{
//do db stuff in here
});
return RedirectToAction("Index", "Dashboard");
}