尝试初始化 Azure AD 时出现 404 not found 错误 [英] 404 not found error when trying to initialize Azure AD

查看:56
本文介绍了尝试初始化 Azure AD 时出现 404 not found 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 ASP.NET WebForms 应用程序上实施 Azure AD.在 Web.Config 中,我添加了以下信息:

I am trying to implement Azure AD on an ASP.NET WebForms application. In the Web.Config, I have added below information:

<add key="ida:RedirectUri" value="https://localhost:44320/" />
<!--Directory_Name.onmicrosoft.com-->
<add key="ida:Tenant" value="https://login.microsoftonline.com/000..." />
<!--App ID URI of service APP-->
<add key="ida:Audience" value="https://login.microsoftonline.com/000../federationmetadata/2007-06/federationmetadata.xml?appid=00000.." />
<!--Client Application Client ID-->
<add key="ida:TrustedCallerClientId" value="000..." />

Startup.cs 文件调用包含以下方法的 Startup.Auth.cs.

The Startup.cs file calls Startup.Auth.cs which contains below method.

   public void ConfigureAuth_Azure(IAppBuilder app)
    {
        app.UseWindowsAzureActiveDirectoryBearerAuthentication(
            new WindowsAzureActiveDirectoryBearerAuthenticationOptions
            {
                TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
                {
                    ValidAudience = ConfigurationManager.AppSettings["ida:Audience"]
                },
                Tenant = ConfigurationManager.AppSettings["ida:Tenant"]
            }); 
    }

只要碰到这个代码,就会抛出错误:

As soon as it hits this code, it throws error:

System.Net.Http.HttpRequestException HResult=0x80131500
Message=Response 状态码不表示成功:404 (Not成立).源 = 堆栈跟踪:

System.Net.Http.HttpRequestException HResult=0x80131500
Message=Response status code does not indicate success: 404 (Not Found). Source= StackTrace:

推荐答案

试试这个代码.

    public void Configuration(IAppBuilder app)
        {
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
        app.UseCookieAuthentication(new CookieAuthenticationOptions());
        app.UseOpenIdConnectAuthentication(
        new OpenIdConnectAuthenticationOptions
        {
        // Sets the ClientId, authority, RedirectUri as obtained from web.config
        ClientId = clientId,
        Authority = authority,
        RedirectUri = redirectUrl,
        
        // PostLogoutRedirectUri is the page that users will be redirected to after sign-out. In this case, it is using the home page
        PostLogoutRedirectUri = redirectUrl,
        Scope = OpenIdConnectScope.OpenIdProfile,
        ResponseType = OpenIdConnectResponseType.IdToken,
        TokenValidationParameters = new TokenValidationParameters()
        {
        ValidateIssuer = false
        },
        // OpenIdConnectAuthenticationNotifications configures OWIN to send notification of failed authentications to OnAuthenticationFailed method
        Notifications = new OpenIdConnectAuthenticationNotifications
        {
        AuthenticationFailed = OnAuthenticationFailed
      }});
    }



private Task OnAuthenticationFailed(AuthenticationFailedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> context)
    {
    context.HandleResponse();
    context.Response.Redirect("/?errormessage=" + context.Exception.Message);
    return Task.FromResult(0);
     }

您可以在 Github 中遵循以下代码示例
(https://github.com/azure-cxp-community/Azure-CXP-Community-Engineering/tree/master/src/DeveloperTools/WebApp.OpenIdConnect.Guide)

You can follow the below code sample in Github
(https://github.com/azure-cxp-community/Azure-CXP-Community-Engineering/tree/master/src/DeveloperTools/WebApp.OpenIdConnect.Guide)

还要检查这个 链接

这篇关于尝试初始化 Azure AD 时出现 404 not found 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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