以下是一个使用ASP.NET MVC和WS Federation实现单点注销的示例代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.IdentityModel.Services;
namespace YourApplication
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
FederatedAuthentication.WSFederationAuthenticationModule.SignOutUrl = "Your WS-Federation Sign Out Url";
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IdentityModel.Services;
namespace YourApplication.Controllers
{
public class AccountController : Controller
{
// 单点注销
public ActionResult Logout()
{
FederatedAuthentication.SessionAuthenticationModule.DeleteSessionTokenCookie();
FederatedAuthentication.SessionAuthenticationModule.SignOut();
return RedirectToAction("Index", "Home");
}
}
}
@{
Layout = null;
}
Logout
Logout
您已成功注销。
@{
ViewBag.Title = "Home Page";
}
Welcome to the Home Page
Please click here to logout.
这个示例代码展示了如何使用ASP.NET MVC和WS-Federation实现单点注销。当用户点击注销链接时,将调用AccountController中的Logout方法,执行单点注销操作。然后用户将被重定向到主页,并显示一个注销成功的消息。