身份的注册方法不适用于IIS

时间:2019-04-06 08:14:56

标签: c# model-view-controller identity

当我在本地运行我的应用程序时,我已经实现了ASP.NET身份管理,并且工作正常。然后,我将其部署到IIS,现在Identity中帐户控制器的“注册”方法引发了未经授权的响应。

我也更新了我的连接字符串。即使我从Postman命中了相同的URL,我也得到了“ 200 OK”的结果。那是用户被插入“ AspNetUsers”表中

请帮助出现问题。 部署应用程序时出错了。我已经像新部署了5次一样。

我的注册方法:-

// POST api/Account/Register
    [AllowAnonymous]
    [Route("Register")]
    public HttpResponseMessage Register(RegisterBindingModel model)
    {
        HttpResponseMessage httpResponseMessage = new HttpResponseMessage();
        if (!ModelState.IsValid)
        {
            return Request.CreateResponse(HttpStatusCode.OK, modelError.CreateModelError(ModelState));
        }
        try
        {
            var user = new ApplicationUser() { UserName = model.UserName, Email = model.Email };

            IdentityResult result = UserManager.Create(user, model.UserName);

            if (!result.Succeeded)
            {
                httpResponseMessage.Content.Headers.Add("Identity_Insert", "Failed");
                httpResponseMessage.StatusCode = HttpStatusCode.InternalServerError;
            }
        }
        catch (Exception ex)
        {
            employeeMaster.LogError<EmployeeMaster>(ex, Global.Class.Common.ErrorType.APIError, 0);
            httpResponseMessage.StatusCode = HttpStatusCode.InternalServerError;
        }
        return httpResponseMessage;
    }

0 个答案:

没有答案