2017-04-06 71 views
0

我試圖將Microsoft Azure Active Directory身份驗證添加到現有的ASP.NET Web應用程序。我無法將此項目轉換爲MVC模式。現有的應用程序已經有一個認證系統。我必須保留它。在Web應用程序中檢查Azure身份驗證

這裏是用來調用蔚藍認證服務代碼:

HttpContext.Current.GetOwinContext().Authentication.Challenge(
      new AuthenticationProperties { RedirectUri = "/" }, 
      OpenIdConnectAuthenticationDefaults.AuthenticationType); 

上面的代碼提示正確Azure的驗證頁面。但是,如何檢查用戶是否成功通過身份驗證? 在MVC模式中,您只需檢查Request.IsAuthenticated如何在此處執行同樣的操作?

回答

0

Request.IsAuthenticated也適用於asp.net web表單應用程序。請參考下面的代碼:

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; 
+0

IsAuthenticated是因爲我的艾于勒認證 – loustak

+0

Request.IsAuthenticated的總是假的永遠是假的? –

+0

當我與天青聯繫是的,如果我與常規形式連接,它就會成爲現實。但我想能夠與兩種方法連接。 – loustak

相關問題