拒绝使用web.config访问网页

Csh*_*arp 2 asp.net authentication forms-authentication web-config

我搜索了Google和SO帖子,但无法获得解决我问题的任何结果.

我的web.config是:

<location path="~/reports/PayPeriodQtrReport.aspx, ~/reports/PayPeriodDetailReport.aspx">
  <system.web>
    <authorization>
      <allow roles="PayrollReports"/>
      <deny users="*"/>
    </authorization>
  </system.web>
</location>

<location path="~/reports/ManifestAnnualReport.aspx, ~/reports/ManifestDetailedReport.aspx">
  <system.web>
    <authorization>
      <allow roles="ManifestReports"/>
      <deny users="*"/>
    </authorization>
  </system.web>
</location>  
Run Code Online (Sandbox Code Playgroud)

授权按要求工作(意味着具有"PayrollReports"角色的人员,无法在菜单项中看到Manifest Reports,而具有"ManifestReports"角色的人员无法在菜单项中看到Payroll Reports).

问题:
作为具有"PayrollReports"角色的用户,我可以输入我的URL http:\\mysite.com\reports\ManifestDetailedReport.aspx并显示该页面.应该显示的是unauthorizedaccess.aspx

同样,作为具有"ManifestReports"角色的用户,我可以输入我的URL http:\\mysite.com\reports\PayPeriodQtrReport.aspx并显示该页面.应该显示的是unauthorizedaccess.aspx

问题: 使用web.config,如何通过键入url来阻止用户入侵页面?

Mik*_*Dev 5

您需要将每个文件放在它自己的location条目中并删除~/:

<location path="reports/PayPeriodQtrReport.aspx">
  <system.web>
    <authorization>
      <allow roles="PayrollReports"/>
      <deny users="*"/>
    </authorization>
  </system.web>
</location>
Run Code Online (Sandbox Code Playgroud)

等等...

这假设您使用的是RoleProvider.要么使用内置的RoleProvider,要么使用自定义的RoleProvider,它继承自RoleProviderweb.config并在其中正确指定.