【问题标题】:Permission of page for Special Windows Account in ASP.NETASP.NET 中特殊 Windows 帐户的页面权限
【发布时间】:2011-08-08 15:15:43
【问题描述】:

我的公司有报告页面report.aspx。我希望只有特殊的 Windows 帐户可以使用此报告。

例如;

AABBCCDD 是我们Active Directory 中的 4 个不同的Windows Account Name

我们希望仅对 4 个用户使用此报告。其他用户想要访问此报告页面应给出错误消息。 (如:You have no permission

我该怎么做?

我应该在Page_Load() 中写一些代码吗?

【问题讨论】:

    标签: c# .net asp.net authentication permissions


    【解决方案1】:

    这应该通过修改web.config文件来完成,如本文Limit file access to specific users in IIS所示

    编辑: 您可能需要为网站设置默认授权,类似于:

    <configuration>
        <system.web>
            <authentication mode="Windows"/>
            <authorization>
                <deny users="?" />
                <allow users="*" />
            </authorization>
        </system.web>
        <location path="report.aspx">
            <system.web>
                <authorization>
                    <allow users="AA,BB,CC,DD" />
                </authorization>
            </system.web>
        </location>
    </configuration>
    

    在某些情况下,文件中的项目顺序确实很重要,因此我会将 Location 元素放在 System.Web 元素之后,以确保它在为特定页面初始化站点之前初始化站点的身份验证/授权。

    【讨论】:

    • 我同意这种方法,您希望避免在应用程序中对各种 Windows 帐户进行硬编码。让 ASP NET 运行时担心这类事情。
    • 我试过了,但是当我拒绝一个用户访问一个页面时,用户无法访问同一文件夹下的所有页面。我必须同时使用允许和拒绝吗?
    • 位置>
    • 您是否为您的网站实施了任何其他身份验证/授权?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    • 2010-11-01
    • 2011-07-07
    相关资源
    最近更新 更多