[英]using UseCookiesAuthentication to authorize the MVC Controller Action, it works locally, gives issue when the application is deployed in azure
I have the MVC application , using the Owin and Asp.Net Identity, and using the useCookieauthentication
我有MVC 应用程序,使用 Owin 和 Asp.Net Identity,并使用
useCookieauthentication
During login process, I have added the custom claim, and I gets properly sign-in.在登录过程中,我添加了自定义声明,并且可以正确登录。 ```
```
[HttpPost]
public async Task<ActionResult> Login(LoginViewModel loginViewModel)
{
var user = UserManager.FindByName(loginViewModel.UserName);
var signInStatus = UserManager.CheckPassword(user, loginViewModel.Password);
if (signInStatus)
{
user.Claims.Add(new Microsoft.AspNet.Identity.EntityFramework.IdentityUserClaim() { ClaimType = "CustomClaim", ClaimValue = loginViewModel.UserName.Trim() });
SignInManager.SignIn(user, true, false);
return Redirect(url);
}
else
{
ModelState.AddModelError("", "Invalid login attempt.");
return View(loginViewModel);
}
}
When I get the callback to my one of Action method, I try to retrieve Claim Custom Claim that I have stored during login process.当我收到我的 Action 方法之一的回调时,我尝试检索我在登录过程中存储的 Claim Custom Claim。 Locally when I run and debug this code it works correctly as expected.
当我在本地运行和调试此代码时,它按预期正常工作。 But when I deploy the application to azure I am unable to get the custom claim value.
但是当我将应用程序部署到 azure 时,我无法获得自定义声明值。
public ActionResult Index()
{
var claimsPrincipal = System.Web.HttpContext.Current.User as System.Security.Claims.ClaimsPrincipal;
var customClaimValue = claimsPrincipal.Identities.First().Claims.First(x => x.Type.Equals("CustomClaim")).Value;
return View();
}
Couple of things to try, Let me know if it still doesn't work for you, Posting as per my recent experience which i covered in my other answer.尝试几件事,让我知道它是否仍然不适合您,根据我在其他答案中介绍的最近经验发布。
Also please troubleshoot further to understand more on the inner stack details.还请进一步排除故障以了解有关内部堆栈详细信息的更多信息。
**Action to take when request is not authenticated in App Service**
Authentication/Authorization section in the azure portal from LogIn with Azure Active Directory to **Allow Anonymous requests**
.**Action to take when request is not authenticated in App Service**
身份验证/授权部分在 azure 门户中从使用 Azure Active Directory 登录到**Allow Anonymous requests**
。 As shown on the picture below:If above option doesn't work out try below:如果上述选项不起作用,请尝试以下操作:
Try changing the application manifest of the application definition on Azure to set the "oauth2AllowIdTokenImplicitFlow" property to true from false.尝试更改 Azure 上应用程序定义的应用程序清单,以将“oauth2AllowIdTokenImplicitFlow”属性从 false 设置为 true。
Asp.net UseOpenIdConnectAuthentication not working in Azure Asp.net UseOpenIdConnectAuthentication 在 Azure 中不起作用
Hope it helps.希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.