在Web应用程序中检查Azure身份验证 [英] Check Azure Authentication in Web Application
问题描述
我正在尝试将Microsoft Azure Active Directory身份验证添加到现有的ASP.NET Web应用程序中.我无法将此项目转换为MVC模式.现有应用程序已经具有身份验证系统.我必须保留它.
I'm trying to add Microsoft Azure Active Directory Authentication to an existent ASP.NET Web Application. I can't convert this project to the MVC pattern. The existing application already have an authentication system. I must keep it.
这是用于调用azure身份验证服务的代码:
Here is the code used to call the azure authentication service :
HttpContext.Current.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties { RedirectUri = "/" },
OpenIdConnectAuthenticationDefaults.AuthenticationType);
前面的代码提示正确的Azure身份验证页面.但是,如何检查用户是否成功通过身份验证? 在MVC模式中,您只需要检查Request.IsAuthenticated,我如何在这里做同样的事情?
The previous code prompt the correct Azure Authentication page. 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 ?
推荐答案
Request.IsAuthenticated也可以在asp.net Web窗体应用程序中使用.请参考以下代码:
Request.IsAuthenticated also works in asp.net web forms application . 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");
}
}
您也可以尝试:
bool IsAuthenticated = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
这篇关于在Web应用程序中检查Azure身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!