%@ WebHandler Language="C#" Class="if_in" Debug="true" %>
using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.IO;
using eMIS.Data;
using System.Data.Common;
using System.Web.SessionState;
using eMIS;
using System.Web.Security;
public class if_in : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest (HttpContext context)
{
string userId = context.Request.QueryString["uid"].ToString();
string recid=context.Request.QueryString["recid"]==null? "" : context.Request.QueryString["recid"].ToString();
string url = context.Request.QueryString["url"] == null ? "" : context.Request.QueryString["url"].ToString();
Double timestamp = Convert.ToDouble(context.Request.QueryString["dt"].ToString());
DateTime d = new DateTime(1970, 1, 1, 8, 0, 0).AddSeconds(timestamp);
string token = context.Request.QueryString["token"].ToString();
string pwd = userId +DateTimeToStamp(d) + "here.in";
pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "MD5").ToLower() ;
//context.Response.Write(pwd);
//context.Response.End();
string errinfo="";
if (pwd == token)
{
if (ExecDateDiff(d, DateTime.Now) > 30)
{
errinfo = "凭证过期";
}
}
else
{
errinfo = "验证凭证失败";
}
if (errinfo != "")
{
context.Response.ContentType = "text/html";
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
context.Response.Write(errinfo);
}
else
{
if (context.Session["userid"] == null)
{
LoginManager lm = new LoginManager(context);
lm.Login(userId);
}
string cookies_name = "_user";
HttpCookie usercookie = new HttpCookie(cookies_name);
usercookie.Values["userid"] = userId;
// usercookie.Values["dd_uid"] = dd_uid;
usercookie.Values["board"] = "app";
eDbManager manager = new eDbManager(WebConfigManager.DefaultDb);
eDbOperator dbo = manager.CreateDbOperator();
string xm = Convert.ToString(dbo.ExecuteScalar("select xingming from com_yhb where id=" + userId));
usercookie.Values["xm"] =xm;
usercookie.HttpOnly = true;
usercookie.Expires = DateTime.MaxValue;
string redirurl = string.Empty;
switch (url)
{
case "main": redirurl = "AllApplication.aspx?";break;
case "todo": redirurl = "task.aspx?";break;
case "done": redirurl = "DoneWorkTask.aspx?";break;
case "msg": redirurl = "message.aspx?";break;
case "news": redirurl = "/frame/default/NewsContent2.aspx?ID="+recid+"&";break;
}
context.Response.Redirect(redirurl+DateTime.Now.Ticks.ToString());
}
}
// 时间转时间戳
public string DateTimeToStamp(DateTime now)
{
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区
long timeStamp = (long)(now - startTime).TotalMilliseconds; // 相差毫秒数
timeStamp = timeStamp / 1000;
return timeStamp.ToString();
}
///
/// 程序执行时间测试
///
/// 开始时间
/// 结束时间
/// 返回(秒)单位,比如: 0.00239秒
public double ExecDateDiff(DateTime dateBegin, DateTime dateEnd)
{
TimeSpan ts1 = new TimeSpan(dateBegin.Ticks);
TimeSpan ts2 = new TimeSpan(dateEnd.Ticks);
TimeSpan ts3 = ts1.Subtract(ts2).Duration();
//你想转的格式
//return ts3.TotalSeconds;
return ts3.TotalDays;
}
public bool IsReusable
{
get
{
return false;
}
}
}