简体   繁体   中英

ASP.NET 5 returns 502.3 – Bad Gateway

Given: A new empty ASP.NET 5 beta8 project. I added some controller and basic views which are working.

A Controller like this:

public class AccountController : Microsoft.AspNet.Mvc.Controller
{
    [HttpPost]
    public async Task<ActionResult> Login(LoginViewModel vm)
    {
        if (ModelState.IsValid)
        {
            var result = await signInManager.PasswordSignInAsync(vm.UserName, vm.Password, vm.RememberMe, false);

            if (result.Succeeded)
            {
                return RedirectToAction("Index", "Home");
            }
        }

        return View();
    }
}

Problem:

When I try to call the this services I get the error page with a BadRequest I 've a breakpoing at the first line of code ( ModelState.IsValid ) which is not called.

Am I missing something?

I find the reason and it was not obivious what it was i post it as answer to my own questions as I think this could save someone a lot of time.

In-Short:

As a summary i would say, that invalid Exceptions in Services which are added to the serviceCollection could lead to this error when they are for first time injected.

Details

I Added a custom UserStore to the ServiceCollection

   services.AddIdentity<MyUser, MyUserRole>(config =>
            {
                config.User.RequireUniqueEmail = true;
            })
                .AddUserStore<MongoUserStore>()
                .AddRoleStore<MongoUserStore>();

The Problem was that MongoUserStore Implemented a wrong interface. It implemented IRoleStore<MyUser> instead of IRoleStore<MyUserRole> . And as the controller recevied a instanz of the SignInManager there were invalidoperation exceptions which did not bubble up. As I fixed this, the service is working

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM