首页 > 解决方案 > 身份的注册方法在 IIS 上不起作用

问题描述

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

我也更新了我的连接字符串。即使我从 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;
    }

标签: c#model-view-controlleridentity

解决方案


推荐阅读