page 继承一个验证类,来实现验证的。以前一直可以的,但是我在页面上 加了<% =变量 %>这样子的输出后,验证就失效了。谁知道为什么吗?
普通页面继承:bagepage如:
public partial class mypage: Permission.BasePage验证类basepage,的函数如下:
protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);
Response.Cache.SetNoStore();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.AddHeader("Pragma", "no-cache");//Tell proxy servers not to cache the page.
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
if (!Context.User.Identity.IsAuthenticated) 
{
string BackUrl=this.Request.Url.ToString();
                ClientScript.RegisterClientScriptBlock(this.GetType(),"NotLoginMsg", "<script language=\"javascript\">alert(\"\n对不起!您还未登录系统或会话已超时,请重新登录!\");top.location.replace('http://"
                    + Request.ServerVariables["Http_Host"] + "/Login.aspx?BackUrl=" + BackUrl + "');</script>");
    
            }
} /// <summary>
/// 复写System.Web.UI.Page的 OnPreRender() 方法
/// </summary>
/// <param name="e"></param>
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender (e);
}

解决方案 »

  1.   

    <% =变量 %> 没看到在哪里。还有,不建议你重写OnLoad来做验证。写在Global文件里面就很方便了。
      

  2.   

    谢谢楼上的.~已经找到原因.原因是页面里面的form没有runat=server 。导致验证类里面的 OnPreRender 没用。
    另外, Global 文件里面做验证怎么实现呢?
      

  3.   

    我是写在 Global文件的Application_BeginRequest里。这样不必每个页面都继承你所写的那个类。Application_BeginRequest你看这个字面饿意思就是在页面加载的时候先执行的方法。把你的验证类移植到这个方法里面来实现就可以了。
    你可以尝试将以下代码复制替换你Global中的Application_BeginRequest试试看。 protected void Application_BeginRequest(Object sender, EventArgs e)
    {
    try{
    if(Request.QuertString["passwd"].ToString()!="11")
    {
    Response.Write("拒绝进入");
    Response.End();
    }
    }
    catch
    {
    Response.Write("拒绝进入");
    Response.End();
    }
    }