我现在想实现一个效果,如果Session里面有值,就继续访问页面,如果没有就跳转到相应的页面处理Session。我的HttpHandlers处理类的代码如下:public class Handlers : IHttpHandler, IRequiresSessionState
{
#region IHttpHandler 成员 public bool IsReusable
{
get { return true; }
} public void ProcessRequest(HttpContext context)
{
//context.Response.Write("Hello Word!");
//context.Response.End();
if (context.Session["userBean"] == null)
{
context.Response.Redirect("../SessionHandler.aspx");
context.Response.End();
}
}
#endregion
}
我现在遇到的问题是:如果Session没有值,跳转正常,并且跳转的页面的内容照常显示;如果有了Session值也跳转正常,但是跳转以后的页面的内容就不显示,跳转以后的页面一片空白。
我刚回顾这些基础,一下想不起来问题处在那,希望大家帮帮忙。
{
#region IHttpHandler 成员 public bool IsReusable
{
get { return true; }
} public void ProcessRequest(HttpContext context)
{
//context.Response.Write("Hello Word!");
//context.Response.End();
if (context.Session["userBean"] == null)
{
context.Response.Redirect("../SessionHandler.aspx");
context.Response.End();
}
}
#endregion
}
我现在遇到的问题是:如果Session没有值,跳转正常,并且跳转的页面的内容照常显示;如果有了Session值也跳转正常,但是跳转以后的页面的内容就不显示,跳转以后的页面一片空白。
我刚回顾这些基础,一下想不起来问题处在那,希望大家帮帮忙。
您没看懂我的意思,我是说如果Session存在值,跳转才出的问题,谢谢!
if (context.Session["userBean"] == null)
{
context.Response.Redirect("../SessionHandler.aspx");//此处加断点试试
context.Response.End();
}
另外看看是否有重复提交?
所有你写在Page内的东西无法呈现出来所以如果是aspx页的除特别需要外不要重新实现IHttpHandler接口你的要求解决方法:重写一个Page类继承System.Web.UI.Page:如public class BasePage : System.Web.UI.Page
{
protected override void OnLoad(System.EventArgs e)
{
//here write your program
base.OnLoad(e);
}
}页面的CS 继承System.Web.UI.Page改为 BasePage
您这么说我已经有点映像了,但是现在是我的HTM页面也是那,跳转以后里面的内容也不显示?
您好,您没有看懂我的问题,我只想搞懂利用HttpHandlers做判断以后页面为什么不能出现内容? 谢谢!
我不是想问判断的问题,而是想问为什么利用HttpHandlers处理以后内容不显示,ASPX页面不显示,HTML页面也不显示!
public void ProcessRequest(HttpContext context)
{
context.Response.WriteFile(context.Server.MapPath(context.Request.Url.LocalPath));//把文件内容输出来,html符合要求
context.Response.End();
}
using System.Web;
namespace MyModule
{
public class MyModule : IHttpModule
{
public void Init(HttpApplication application)
{
application. AcquireRequestState += (new
EventHandler(this.Application_AcquireRequestState));
}
private void Application_AcquireRequestState (Object source,
EventArgs e)
{
HttpApplication Application = (HttpApplication)source;
string url=Application.Context.Request.Path;
if(Application.Context.Sesseion[ "User "] ==null)
Application.Context.Server.Transfer( "ErrorPage.aspx "); }
public void Dispose()
{
}
}
}
或使用BasePage
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lijunchen1007/archive/2009/06/22/4288140.aspx
{
// closeWindow();
HttpContext ctx = HttpContext.Current;
HttpResponse response = ctx.Response;
HttpRequest request = ctx.Request; Exception exception = ctx.Server.GetLastError(); // string errorInfo = "应用程序发生错误!<br/>1,来源地址:" + ctx.Request.Url.ToString() + "<br/>2,错误信息:" + exception.InnerException.Message;
string errorInfo = "<table><tr><td>1</td></tr><tr><td>2</td></tr><tr><td style='width: 23px; color: red'>ErrorInfo</td></tr></table>";
response.Write(errorInfo); ctx.Server.ClearError();
}
这样OK?