asp.net。初学编程。求如何ashx获取Session或者Cookies中的用户名
asp.net。初学编程 ,求如何通过读取Session或者Cookies中的用户名
然后下面这个imageUp.ashx接收
主要是imageUp.ashx如何获得Cookies的用户名?然后pathbase = 用户名+"/" ;
<%@ WebHandler Language="C#" Class="imageUp" %>
<%@ Assembly Src="Uploader.cs" %>
using System;
using System.Web;
using System.IO;
using System.Collections;
public class imageUp : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//上传配置
int size = 2; //文件大小限制,单位MB //文件大小限制,单位MB
string[] filetype = { ".gif", ".png", ".jpg", ".jpeg", ".bmp" }; //文件允许格式
//上传图片
Hashtable info = new Hashtable();
Uploader up = new Uploader();
string pathbase = null;
int path=Convert.ToInt32( up.getOtherInfo(context, "dir"));
if (path == 1)
{
pathbase = "upload/" ;
}else{
pathbase = "upload1/";
}
info = up.upFile(context, pathbase, filetype, size); //获取上传状态
string title = up.getOtherInfo(context, "pictitle"); //获取图片描述
string oriName = up.getOtherInfo(context, "fileName"); //获取原始文件名
HttpContext.Current.Response.Write("{'url':'" + info["url"] + "','title':'" + title + "','original':'" + oriName + "','state':'" + info["state"] + "'}"); //向浏览器返回数据json数据
}
public bool IsReusable
{
get
{
return false;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
HttpCookie cookie = Request.Cookies["chp6"];
string sid;
if (cookie != null)
{
sid = cookie["sid"];
}
else
{
cookie = new HttpCookie("chp6");
Guid gid = new Guid();
sid = gid.ToString();
cookie["sid"] = sid;
}
Session[sid] = tbUserName.Text;
cookie.Expires = DateTime.Now.AddMinutes(30);
Response.Cookies.Add(cookie);
Response.Redirect("~/Cookie2.aspx");
}
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie cookie = Request.Cookies["chp6"];
if (cookie != null)
{
string sid = cookie["sid"];
string uname = Session[sid] as string;
lbUserName.Text = uname == null ? "未登录" : uname;
}
else
lbUserName.Text = "未登录";
}
context.Request.Cookies["id"];
context.Session["id"];
[解决办法]
ashx文件也是一样,只不过cookie是从context.Request.Cookies里获取
[解决办法]
[解决办法]
不客气,这是一个互相提高的过程
[解决办法]
imageUp:IHttpHandler:IRequiresSessionState
[解决办法]
这个应该简单,呵呵。。。