在Web应用程序中检查Azure身份验证 [英] Check Azure Authentication in Web Application

查看:96
本文介绍了在Web应用程序中检查Azure身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆