使用ADFS ASP.NET MVC登录后如何更改重定向控制器?

时间:2019-09-18 22:53:28

标签: c# asp.net-mvc adfs ws-federation

我正在ASP.NET MVC应用程序中执行联合身份验证,为此我使用以下配置代码

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        // Para obtener más información sobre cómo configurar la aplicación, visite https://go.microsoft.com/fwlink/?LinkID=316888
        ConfigureAuth(app);
    }

    public void ConfigureAuth(IAppBuilder app)
    {
        app.UseCookieAuthentication(
        new CookieAuthenticationOptions
        {
            AuthenticationType = CookieAuthenticationDefaults.AuthenticationType
        });
        app.UseWsFederationAuthentication(
        new WsFederationAuthenticationOptions
        {
            MetadataAddress = "https://example.com/FederationMetadata/2007-06/FederationMetadata.xml",
            Wtrealm = "https://example.com/appId",
        });

        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
    }
}

AccountController

public class AccountController : Controller
{
    public void SignIn()
    {
        if (!Request.IsAuthenticated)
        {
            HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/" }, 
                WsFederationAuthenticationDefaults.AuthenticationType);
        }
    }

    public void SignOut()
    {
        string callbackUrl = Url.Action("SignOutCallback", "Account", routeValues: null, protocol: Request.Url.Scheme);

        HttpContext.GetOwinContext().Authentication.SignOut(
            new AuthenticationProperties { RedirectUri = callbackUrl },
            WsFederationAuthenticationDefaults.AuthenticationType, CookieAuthenticationDefaults.AuthenticationType);
    }

    public ActionResult SignOutCallback()
    {
        if (Request.IsAuthenticated)
        {
            // Redirigir a la página principal si el usuario está autenticado.
            return RedirectToAction("Index", "Inicio");
        }

        return View();
    }
}

登录成功,但是,我想做的是在登录时,转到另一个控制器,例如:Home / Main。

问题是我不了解mvc项目如何使用联合身份验证,它不知道登录后应执行的操作或控制器,因为未进行任何配置。

如何在成功登录后更改或配置控制器以进入?

0 个答案:

没有答案