asp.net中使用forms驗證

來源:互聯網
上載者:User

標籤:style   class   blog   code   http   color   

1、首先在web.config中修改驗證方式為 "Forms" <authentication mode="Forms"> 這裡的模式有很多中,可自己去百度

2、在<authentication mode="Forms"></authentication>中添加:

<forms name="loginAuth" protection="All" loginUrl="login.aspx" defaultUrl="Default.aspx" path="/" timeout="20"></forms>

  這裡的參數說明 ,參見:http://msdn.microsoft.com/zh-cn/library/1d3t3c61(v=vs.80).aspx

3、如果所有頁面在未驗證通過的情況下都不能訪問,"?"表示匿名使用者,"*"表示所有使用者。

<authorization>    <deny users="?"/></authorization>

4、如果某一個頁面可以在不登陸的情況下訪問該怎麼辦呢?下面解決辦法:

  在</system.web>後面添加如下:

<location path="about.aspx">    <system.web>        <authorization>            <allow users="*"/>        </authorization>    </system.web></location>

  添加後除了"about.aspx"任何人能訪問,其它的頁面都不能訪問,如果訪問其它任何一個頁面將會跳轉到forms中loginUrl參數中指定的檔案去

設定好後就一勞永逸了。

註:本人菜鳥一個!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.