如何在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);
            }
   注意:在整個項目中,無論點擊那個頁面都會跳轉到登錄頁面;登錄成功之後纔會跳轉到自己剛剛指定的頁面。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章