[英]Check Azure Authentication in Web Application
I'm trying to add Microsoft Azure Active Directory Authentication to an existent ASP.NET Web Application. 我正在尝试将Microsoft Azure Active Directory身份验证添加到现有的ASP.NET Web应用程序中。 I can't convert this project to the MVC pattern.
我无法将此项目转换为MVC模式。 The existing application already have an authentication system.
现有应用程序已经具有身份验证系统。 I must keep it.
我必须保留。
Here is the code used to call the azure authentication service : 这是用于调用Azure身份验证服务的代码:
HttpContext.Current.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties { RedirectUri = "/" },
OpenIdConnectAuthenticationDefaults.AuthenticationType);
The previous code prompt the correct Azure Authentication page. 前面的代码提示正确的Azure身份验证页面。 But how can I check if the user authenticated successfully ?
但是,如何检查用户是否成功通过身份验证? In MVC pattern you just have to check Request.IsAuthenticated how can I do the same here ?
在MVC模式中,您只需要检查Request.IsAuthenticated,在这里我该怎么做?
Request.IsAuthenticated also works in asp.net web forms application . Request.IsAuthenticated也可以在asp.net Web窗体应用程序中使用。 Please refer to below code :
请参考以下代码:
private void Page_Load(object sender, EventArgs e)
{
// Check whether the current request has been
// authenticated. If it has not, redirect the
// user to the Login.aspx page.
if (!Request.IsAuthenticated)
{
Response.Redirect("Login.aspx");
}
}
You could also try : 您也可以尝试:
bool IsAuthenticated = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.