如何在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);
            }
   注意:在整个项目中,无论点击那个页面都会跳转到登录页面;登录成功之后才会跳转到自己刚刚指定的页面。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值