[英]How to use Authentication and Authorization in Asp.net MVC 4 application?
[英]How to use Authorization & Authentication in Asp.net, C#?
我正在使用Roll Management,並且嘗試根據用戶或用戶組來授予頁面和文件夾訪問權限,並且還使用服務器創建的AD組進行用戶身份驗證。
我有default1.aspx
頁面作為默認目錄,而subdir1
文件夾為單獨的用戶組提供了不同的訪問權限
我在web.config中使用以下邏輯。
<location path="subdir1">
<system.web>
<authorization>
<allow users ="?" />
</authorization>
</system.web>
</location>
我面臨向同一用戶提供對2個或更多目錄的相同訪問權限的問題,因此我是否必須為兩個文件夾提供兩次允許用戶代碼?
我可以通過為所有文件夾重復值來使用此邏輯,但是我想用一種邏輯來提供所有訪問權限。
我已經得到配置文件夾/頁面訪問的答案,為此,我必須進行如下所示的其他訪問。
配置對特定文件和文件夾的訪問,設置基於表單的身份驗證。 請求將應用程序中的任何頁面自動重定向到Logon.aspx。
在Web.config文件中,執行以下代碼。
此代碼授予所有用戶訪問Default1.aspx頁和Subdir1文件夾的權限。
<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 Default1.aspx page only. It is located in the same folder as this configuration file. -->
<location path="default1.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 Subdir1 folder. -->
<location path="subdir1">
<system.web>
<authorization>
<allow users ="*" />
</authorization>
</system.web>
</location>
</configuration>
用戶可以打開Default1.aspx文件或保存在應用程序的Subdir1文件夾中的任何其他文件。 它們不會自動重定向到Logon.aspx文件進行身份驗證。
重復配置步驟,確定要允許未經身份驗證的用戶訪問的所有其他頁面或文件夾。
有關更多參考,請查看Microsoft支持頁面-https://support.microsoft.com/zh-cn/kb/301240
您也可以檢查http://www.iis.net/configreference/system.webserver/security/authorization
在必須對登錄頁面進行編碼以供參考后,請檢查此-> http://www.codeproject.com/Articles/13872/Form-authentication-and-authorization-in-ASP-NET
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.