62,072
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Validation.aspx.cs" Inherits="WebCrm.Validation" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="jquery-easyui-1.4/themes/default/easyui.css" rel="stylesheet" />
<link href="jquery-easyui-1.4/themes/icon.css" rel="stylesheet" />
<script src="jquery-easyui-1.4/jquery.min.js" type="text/javascript"></script>
<script src="jquery-easyui-1.4/jquery.easyui.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="Styles/admin-all.css" />
<script type="text/javascript">
function Send() {
var loginUserId = $("#<%=LoginID.ClientID%>").val();
$.ajax({
//提交方式
type: "Post",
//路径
url: "Code/ValidCode.ashx?Method=Send",
data: {
Loginid: loginUserId,
d: new Date()
},
dataType: "text",
//返回数据-需要返回JSON格式的数据(Jquery 1.4版本+以后要求返回数据格式是严格的JSON格式的数据)
success: function (json) {
alert(json);
//if (json.MessageText == 1) {
// alert("发送邮件成功.");
//} else if (json.MessageText == 0) {
// alert("Send mail success.");
//}
},
error: function (e) {
alert(e);
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:HiddenField runat="server" ID="LoginID" />
<div align="center">
<table width="300px;">
<tr>
<td colspan="3">
<asp:Label runat="server" Text="请点击'发送验证码'按钮发送验证码到你的邮箱 " Font-Names="幼圆" Font-Size="Small" ForeColor="Blue"></asp:Label>
</td>
</tr>
<tr>
<td>
<input type="text" id="inpvalidationCode" style="width: 211px;" />
</td>
<td>
<button id="butvalidation" class="black" style="width: 122px; height: 25px;">验证</button>
</td>
<td>
<button id="butSend" class="black" style="width: 131px; height: 25px;" onclick="javascript:Send();">发送验证码</button>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.SessionState;
using Entity;
using Newtonsoft.Json;
namespace WebCrm.Code
{
/// <summary>
/// ValidCode 的摘要说明
/// </summary>
public class ValidCode : IHttpHandler
{
HttpContext _httpContext;
HttpCookie _cookie;
public void ProcessRequest(HttpContext context)
{
//不让浏览器缓存
context.Response.ContentType = "text/plain";
//context.Response.Buffer = true;
//context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
//context.Response.AddHeader("pragma", "no-cache");
//context.Response.AddHeader("cache-control", "");
//context.Response.CacheControl = "no-cache";
_httpContext = context;
string method = _httpContext.Request["Method"].ToString();
MethodInfo methodInfo = this.GetType().GetMethod(method);
methodInfo.Invoke(this, null);
}
/// <summary>
/// 发送验证码
/// </summary>
public void Send()
{
//Json数据返回格式
Entity.ReturnsData returnsData = new Entity.ReturnsData();
//获取对象值
string login = _httpContext.Request["Loginid"];
//获取当前用户缓存
Entity.LoginInfo loginInfo = BLL.CacheBll.GetCache(login) as Entity.LoginInfo;
if (loginInfo != null)
{
int d = 0;
//判断当前是否存在Cookies
if (_httpContext.Request.Cookies["ValidInfo"] == null)
{
Random rand = new Random();
d = rand.Next(100001, 999999);
//Session["ValidCode"] = d;
TimeSpan ts = new TimeSpan(0, 0, 15, 00);//cookie有效作用时间
_cookie = new HttpCookie("ValidInfo");
_cookie.Expires = DateTime.Now.Add(ts);
_cookie.Values.Add("ValidCode", d.ToString());
_httpContext.Response.AppendCookie(_cookie);
BLL.EmailHelper.SendMail(d, loginInfo.DefaultMail, loginInfo.IsEnglish);
returnsData.MessageText = loginInfo.IsEnglish ? 0 : 1;
_httpContext.Response.Write(returnsData.MessageText);
_httpContext.Response.End();
}
}
}
/// <summary>
/// 验证
/// </summary>
public void Validation()
{
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
if (json== 1) {
alert("发送邮件成功.");
} else {
alert("Send mail success.");
}