[url=Login.aspx]
很简单,就是把Response.Redirect改为Response.Write,输出脚本,实现跳转。
再共享一个,也是关于退出的。
妙用Asp.Net中的HttpHandler
上面的方法我觉得很好,写一个类继承IHttpHandler
public class LogoutHttpHandler : IHttpHandler
{
/// <summary>
/// 通过实现 IHttpHandler 接口的自定义 HttpHandler 启用 HTTP Web 请求的处理。
/// </summary>
/// <param name="context">HttpContext 对象,它提供对用于为 HTTP 请求提供服务的内部服务器对象(如 Request、Response、Session 和 Server)的引用。 </param>
public void ProcessRequest (HttpContext context)
{
FormsAuthentication.SignOut();
context.Response.Redirect("Login.aspx",true);
}
再修改web.config,在<system.web></system.web>中增加如下脚本:
[url=Login.aspx]}
}
这样不用再加一个页面Logout.aspx,退出的代码也简单。
protected void Exit_Click(object sender, EventArgs e)
{
Response.Redirect("Logout.aspx");
}