一般处理程序写弹框及链接跳转

请求一般处理程序后,如果验证结果不正确,需要弹框返回提示

下面为所写的一个类,供一般处理程序调用

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");

            }

        }

    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值