我正在尝试开发一个MVC ASP.NET C#应用程序,它能够支持Azure AD身份验证和表单身份验证。
我已经阅读了相关信息,并得出以下结论:
我有一个登录表单用于表单身份验证,以及一个按钮,可将我重定向到Azure AD登录页面。
在我登录AD之后,它会自动将我重定向到http://localhost/login.aspx?ReturnUrl=%2f。
使用以下代码:
Startup.cs
我已经阅读了相关信息,并得出以下结论:
我有一个登录表单用于表单身份验证,以及一个按钮,可将我重定向到Azure AD登录页面。
在我登录AD之后,它会自动将我重定向到http://localhost/login.aspx?ReturnUrl=%2f。
使用以下代码:
Startup.cs
public partial class Startup
{
private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
private static string tenant = ConfigurationManager.AppSettings["ida:Tenant"];
private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"];
string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
RedirectUri = postLogoutRedirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = context =>
{
context.HandleResponse();
context.Response.Redirect("/Error?message=" + context.Exception.Message);
return Task.FromResult(0);
}
}
});
}
}
AccountController.cs
public void SignIn()
{
// Send an OpenID Connect sign-in request.
if (!Request.IsAuthenticated)
{
HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationType);
}
}
public void SignOut()
{
// Send an OpenID Connect sign-out request.
HttpContext.GetOwinContext().Authentication.SignOut(
OpenIdConnectAuthenticationDefaults.AuthenticationType, CookieAuthenticationDefaults.AuthenticationType);
}
public void EndSession()
{
// If AAD sends a single sign-out message to the app, end the user's session, but don't redirect to AAD for sign out.
HttpContext.GetOwinContext().Authentication.SignOut(CookieAuthenticationDefaults.AuthenticationType);
}
我的问题是为什么会重定向到 http://localhost/login.aspx?ReturnUrl=%2f,因为我的应用程序是MVC,我的项目中没有aspx。