gpt4 book ai didi

c# - 响应状态码不表示成功 : 404 (Not Found) with owin library

转载 作者:行者123 更新时间:2023-12-03 06:10:33 25 4
gpt4 key购买 nike

我正在尝试在我的 ASP.NET MVC 应用程序(框架版本 4.7.2)上实现 Azure AD 身份验证。

enter image description here

所有必需的配置值都位于 web.config 文件中。

enter image description here

AccountController.cs

public class AccountController : Controller
{
// GET: Account
public ActionResult Index()
{
return View();
}

public void SignIn()
{
if (!Request.IsAuthenticated)
{
HttpContext.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties { RedirectUri = "/Default" },
OpenIdConnectAuthenticationDefaults.AuthenticationType
);
}
}

public void SignOut()
{

HttpContext.GetOwinContext().Authentication.SignOut(
OpenIdConnectAuthenticationDefaults.AuthenticationType,
CookieAuthenticationDefaults.AuthenticationType
);
}
}

RouteConfig.cs

public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}

enter image description here

当我尝试调用 SignIn 方法时,它总是显示错误,如下图所示。

enter image description here

最佳答案

The error occurred as you missed adding {0} to the AADInstance key in your Web.config file.

我关注了这个blog@ayoub 在我的 .NET MVC 应用程序(框架 4.7.2)中实现 Azure AD 身份验证。

当我点击登录按钮时,未将 {0} 添加到 Web.config 中的 AADInstance key 文件,我也遇到了同样的错误:

<appSettings>
<add key="ida:ClientId" value="appID" />
<add key="ida:Tenant" value="xxxxxxxx.onmicrosoft.com" />
<add key="ida:AADInstance" value="https://login.microsoftonline.com/" />
<add key="ida:PostLogoutRedirectUri" value="https://localhost:44353/" />
</appSettings>

回应:

enter image description here

解决该错误,请确保通过修改 Web.config 文件在 AADInstance 键值末尾添加 {0} :

<appSettings>
<add key="ida:ClientId" value="appID" />
<add key="ida:Tenant" value="xxxxxxxx.onmicrosoft.com" />
<add key="ida:AADInstance" value="https://login.microsoftonline.com/{0}" />
<add key="ida:PostLogoutRedirectUri" value="https://localhost:44353/" />
</appSettings>

现在,我通过进行上述更改再次运行该项目,并使用登录按钮进入屏幕下方:

enter image description here

当我单击登录按钮时,我看到下面的屏幕来选择 Azure AD 帐户:

enter image description here

登录成功后,我会进入/Home/Index页面:

enter image description here

引用: asp.net mvc - Azure AD Signin from MVC: Response status code does not indicate success: 404 (Not Found) by AxleWack

关于c# - 响应状态码不表示成功 : 404 (Not Found) with owin library,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76851821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com