首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

小弟初学者,跪求关于Session的有关问题

2013-04-09 
小弟菜鸟,跪求关于Session的问题!%@ Page LanguageC# AutoEventWireuptrue CodeFileS2.aspx.cs

小弟菜鸟,跪求关于Session的问题!

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="S2.aspx.cs" Inherits="S2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" action="S4.ashx" runat="server">
    <div>
  

    <input type="text" name="LoginId" /><br />
    <input type=text name="LoginPwd" /><br />
    <input type="submit" value="login" />
    </div>
    </form>
</body>
</html>

//↑↑↑上边是第一个web窗体
//第一个窗体的form把值传给下面的ashx     ↓↓↓
<%@ WebHandler Language="C#" Class="S4" %>

using System;
using System.Web;
using System.Web.SessionState;

public class S4 : IHttpHandler,IReadOnlySessionState {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/html";
        string a=context.Request.Form["LoginId"].Trim();
        if (a != null)
        {
            context.Session["aaa"] = a;
            context.Response.Redirect("S3.ashx");
        }
        else
        {

            context.Response.Write("出错了");
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}
//如果检测到有用户名输入的话 则写入一个Session 然后页面跳转到下一个窗体   ↓↓↓
<%@ WebHandler Language="C#" Class="S3" %>

using System;
using System.Web;
using System.Web.SessionState;

public class S3 : IHttpHandler,IReadOnlySessionState {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/html";
        string a =Convert.ToString( context.Session["aaa"]);
        context.Response.Write(a);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }



}

//↑↑↑此窗体只是想显示一下刚才存的session 但是值一直是null!!!小弟跪求原因!望大神解答!谢谢!!! Session?传值?null
[解决办法]
实现该接口:IRequiresSessionState   
[解决办法]
if (a != null)
        {
            context.Session["aaa"] = a;
            context.Response.Redirect("S3.ashx");
        }
a为null不?给Session赋值的语句有没有执行?还有,你继承的是IReadOnlySessionState,这个从名字上看就是只读的吧。。,

热点排行