请求一般处理程序后,如果验证结果不正确,需要弹框返回提示
下面为所写的一个类,供一般处理程序调用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace TestSpace{
public class Alert
{
/// <summary>
/// 跳转到登录成功页面
/// </summary>
/// <param name="url">跳转链接</param>
/// <param name="message"></param>
public static void Redirect(string url, string message = "登录成功")
{
ResponseScript("window.location = '" + url + "';");
}
/// <summary>
/// 弹框,并返回上一页
/// </summary>
/// <param name="message"></param>
public static void AlertFailed(string message = "登录失败")
{
ResponseScript("alert('" + message + "');javascript:history.go(-1);");
}
/// <summary>
/// Script脚本
/// </summary>
/// <param name="script"></param>
public static void ResponseScript(string script)
{
HttpContext.Current.Response.Write("<script type=\"text/javascript\">\n//<![CDATA[\n");
HttpContext.Current.Response.Write(script);
HttpContext.Current.Response.Write("\n//]]>\n</script>\n");
}
}
}
using System;
using System.Web;
using System.Web.SessionState;
namespace TestSpace
{
/// <summary>
/// login 的摘要说明
/// </summary>
public class login : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
string action = context.Request.HttpMethod.ToUpper();
if (action!="POST")
{
Alert.AlertFailed("URL请求无效");
return;
}
else
{
Alert.Redirect("Index.aspx");
}
}
}
}