当前位置:编程学习 > 网站相关 >>

如何在web.config里面设置页面跳转问题

<?xml version="1.0"?>
<configuration>
  <appSettings/>
  <connectionStrings/>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
 1,   在这里开始设置
    <authentication mode="Forms">
      <forms loginUrl="login.aspx" defaultUrl="index.aspx" name="aspx"></forms>
loginUrl是指登录的页面,defaultUrl是指登陆后默认的显示页面,name就随便写
    </authentication>
    <authorization>
   2.   <!---拒绝所有匿名用户访问项目下的所有文件-->
      <deny users="?"/>
 3.     <!--设置所有用户都可以访问项目下的所有文件-->
      <!--<allow users="*"/>-->
    </authorization>
  </system.web>


设置为登录页面
  <location path="login">
    <system.web>
      <authorization>
        <deny users="?"/>       
      </authorization>
    </system.web>
4.  上面的设置完成之后,会出现一个问题就是图片不出,然后在加上下面的代码就可以了 
  </location>
  <location path="images">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
5.因为这里涉及到验证码的问题,path就是指的验证码的页面,这一步是跟着上一步来的,需要把
验证码的页面放在images文件夹下面,然后在验证码页面把指向验证码的路径改为在images/ValidateCode. aspx;
  <location path="ValidateCode.aspx">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location> 
</configuration>
6.登陆页面的后台:
  protected void 登陆_Click(object sender, EventArgs e)
        {        
                FormsAuthentication.RedirectFromLoginPage(txtusername.Text,false);       //txtusername就是用户登录时用户名;         
        }


7.index页面后台(这里指登录之后默认显示的页面)
     if(!IsPostBack)
            {
                  Response.Write(Context.User.Identity.Name);
            }
   注意:在整个项目中,无论点击那个页面都会跳转到登录页面;登录成功之后才会跳转到自己刚刚指定的页面。

补充:Web开发 , 其他 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,