if(!Page.IsPostBack)--如果没有登陆,弹出“请登陆”,单击确定后返回登陆页面
最好给一段详细代码。关于页面访问权限的判断,我考虑建一个类,然后受保护页面引用,是要转换成DLL文件吗?不同的权限,如何隐藏相关功能?我知道有一个办法是在HTML里进行隐藏,有更好的办法吗?(初学者)

解决方案 »

  1.   

    if(!IsPostBack)
    {
    if(session["UserID"]==null){
    Response.Write("<script language='javascript'>alert('请登录');window.location.href='index.htm';</script>");
      

  2.   

    我的辦法也是判斷session有沒有值一系列的
      

  3.   

    TO:seeos() 谢谢回复,你的办法可行,但是现在有一个问题,我用的框架,主页index.aspx,我把这段代码加到PAGE_LOAD事件后也能够转到LOGIN.ASPX,但是TOP和LEFT框架还在,也就是说重定向的登陆页面是在框架里面的,怎么做才能让整个页面都重定向到初始的登陆页面(不含框架),不知道我说明白了没有。
      

  4.   

    或者在登陆后自动刷新TOP以及LEFT。现在由于没有刷新SESSION,导致每次反复提示要求登陆
      

  5.   

    更改后的代码如下:
    if(!IsPostBack)
    {
    if(session["UserID"]==null){
    Response.Write("<script language='javascript'>alert('请登录');window.close();window.open(\"Login.aspx\");</script>");
      

  6.   

    Sorry,刚才错了,更改后的代码如下:
    if(!IsPostBack)
    {
    if(session["UserID"]==null){
    Response.Write("<script language='javascript'>alert('请登录');window.open(\"Login.aspx\");window,close();</script>");
      

  7.   

    能打开新窗口了,可是原来的窗口没有关闭。
    window,close()
    我把逗号改成.也没有成功,呵呵!
      

  8.   

    我有个代码是可行的,你参考一下
    <html>
    <head></head>
    <body>
    <frameset>
    <frame src="http://www.baidu.com"></frame>
    </frameset>
    <a href="#" onclick="window.close();window.open('Http://www.google.com');">Close</a>
    </body>
    </html>
      

  9.   

    if(!IsPostBack)
    {
    if(session["UserID"]==null){
    Response.Write("<script language='javascript'>alert('请登录');window.close();window.open(\"Login.aspx\");</script>");
      

  10.   

    搞错了  应该是这样if(!IsPostBack)
    {
    if(session["UserID"]==null){
    Response.Write("<script language='javascript'>alert('请登录');window.close();window.open('Login.aspx');</script>");
      

  11.   

    TOO:xu__huan(挡风人)你的问题问的很好!
    你可以用 Response.Write("<script>window.parent.location.href('url')</script>");
      

  12.   

    问题已经解决了,现在的问题是我有好多受保护页面,一页一页添加太麻烦了,如何生成DLL文件并且进行引用?有答案就结帖了! 
      

  13.   

    用FORM验证就不用一页一页添加,修改WEBCONFIG里面的相关属性就可以
      

  14.   

    楼上:FORM验证怎么做?能详细点吗?
      

  15.   

    用Forms身份验证,一切搞定!看<asp.net 1.1 入门经典>这本书中,专门有一章讲这个你可以看一下,如果还解决不了,加我QQ吧:120854833,我正在研究这个呢!
      

  16.   

    呵呵,谢谢!不过对于我来说时间好像来不及了
    我还是按照我的思路,把以下代码生成DLL文件进行引用
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace XJ
    {
    public class XJ: System.Web.UI.Page
    {private void Page_Load(object sender, System.EventArgs e)

     {
      if(!IsPostBack)
        {
        if(Session["UserName"]==null)
          {
            Response.Write("<script language='javascript'>alert('请先登录!');window.parent.location.href('start.aspx');</script>");
          } 
        }
     }
    }
    }页面加入
    <%@ Import Namespace="XJ" %>
    using XJ;但是不起作用啊!
    我初学,给点方法!
      

  17.   

    比如有一个index.aspx,人人可以访问;一个login.aspx,登录页面;vip.aspx,受保护页面。在VS.Net中可以启用Forms验证。需要先修改 web.config文件。
    <authentication mode="Forms">
       <forms name="AUTHTEST" loginUrl="login.aspx" protection="All" timeout="20"></forms>
    </authentication>
    上面的含义是:启用一个名称为AUTHTEST的Forms验证。 启用Fomrs验证后,要开始设定页面的访问权限了。默认页面index.aspx是都可以访问的,因此设为
    <authorization>
    <allow users="?">  //表示允许匿名访问
    </authorization>VIP目录下的页面设为
    <location path="VIP">
     <system.web>
       <authorization>
         <deny users="?">  //表示拒绝匿名访问
       </authorization>  
     </system.web>
    </location>这样就可以了
      

  18.   

    TO:kof_sdu(虫族男孩) 
    <location path="VIP">中的"VIP“指的就是vip.aspx这个页面吗?那我有好多页面,也需要每一页都加吗?
      

  19.   

    <location path="vip/*.aspx">这样可以把vip目录下所有的  .aspx 页面纳入必须认证
      

  20.   

    好像把Web.config文件设置成基于Form验证就可以了。不知道要的是不是这个
      

  21.   

    top.location.href='login.aspx'
    也能实现页面不在框架中
      

  22.   

    class XJ没错,但是你需要批量替换所有aspx.cs的System.Web.UI.Page为XJ
    可参考http://onewww.net/blog/article.asp?id=25
    然后查找msdn去设置PageBase