Form Authentication issue for two sub folders
In my application there are two sub folders which needs to be authenticated. In my application web.config, i have given like this
<authentication mode="Forms">
<forms loginUrl="Customer/My Accounts/Default.aspx开发者_运维知识库" name="formsauth1"
/>
</authentication>
This will work for only one sub folder having the path Customer/My Accounts/Default.aspx but I need to authenticate another sub folder having path Arab/Customer/My Accounts/Default.aspx. I want to know how to identify both the folders and how to authenticate them by modifying the above said code
You want to set the loginUrl equal to your login page, not the restricted page.
<authentication mode="Forms">
<forms loginUrl="Login.aspx" name="formsauth1" />
</authentication>
Then in the sub folders you want to create a web.config in each with the following:
<configuration>
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</configuration>
So what will happen is that when an unauthenticated user tries to access those sub folders, the <authorization>
element will deny them and redirect them to the loginUrl
. After they log in, they'll be returned to the original page they were trying to access.
精彩评论