我遇到了asp.net上的任務問題。我想問一下,除非我在Web配置中指定對頁面的訪問權限,否則有什麼方法可以阻止任何用戶(包括已通過身份驗證的用戶)訪問新創建的Web表單?asp.net表單身份驗證拒絕任何用戶訪問新的Web表單
我嘗試使用
<deny users="*">
但它拒絕所有用戶訪問任何網頁,甚至是那些我已經指定訪問權限,例如:
<location path="home.aspx">
我遇到了asp.net上的任務問題。我想問一下,除非我在Web配置中指定對頁面的訪問權限,否則有什麼方法可以阻止任何用戶(包括已通過身份驗證的用戶)訪問新創建的Web表單?asp.net表單身份驗證拒絕任何用戶訪問新的Web表單
我嘗試使用
<deny users="*">
但它拒絕所有用戶訪問任何網頁,甚至是那些我已經指定訪問權限,例如:
<location path="home.aspx">
這是一篇好文章看,這個例子是MS Support
<configuration>
<system.web>
<authentication mode="Forms" >
<forms loginUrl="login.aspx" name=".ASPNETAUTH" protection="None" path="/" timeout="20" >
</forms>
</authentication>
<!-- This section denies access to all files in this
application except for those that you have not explicitly
specified by using another setting. -->
<authorization>
<deny users="?" />
</authorization>
</system.web>
<!-- This section gives the unauthenticated
user access to the ThePageThatUnauthenticatedUsersCanVisit.aspx
page only. It is located in the same folder
as this configuration file. -->
<location path="ThePageThatUnauthenticatedUsersCanVisit.aspx">
<system.web>
<authorization>
<allow users ="*" />
</authorization>
</system.web>
</location>
<!-- This section gives the unauthenticated
user access to all of the files that are stored
in the TheDirectoryThatUnauthenticatedUsersCanVisit folder. -->
<location path="TheDirectoryThatUnauthenticatedUsersCanVisit">
<system.web>
<authorization>
<allow users ="*" />
</authorization>
</system.web>
</location>
</configuration>
這應該可以幫助你:
<location path="FolderName/pagename.aspx">
<system.web>
<authorization>
<deny users="*"/>
</authorization>
</system.web>
</location>
嗨,答案要求我已經知道頁面被排除訪問,但我的目標是拒絕所有訪問新的表單,除了那些我已經在web.config設置中指定的。 – csharpnewbie
你只需要提供你想拒絕訪問的位置路徑 – Srinivas
的頁面路徑,但問題是我希望它適用於所有新頁面,我必須知道頁面名稱,然後才能使用您的方法..所以有沒有辦法做到這一點? – csharpnewbie
對不起,我在這裏得到了相當的代碼,我的頁面不在文件夾內,所以我不能在位置路徑中指定文件夾名稱..我想我的問題有點含糊,我的目標是除了我在web.config設置中指定的那些表單之外,拒絕對所有新表單的訪問。 – csharpnewbie