Asp.Net否认在某些网页上的用户访问 [英] Asp.Net deny access on certain pages to users

查看:61
本文介绍了Asp.Net否认在某些网页上的用户访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何允许访问我的web应用程序给用户,但拒绝他们访问特定的页面?我希望让更多的用途使用一个应用程序,我已经建立,但也有几页,我不希望他们能够访问。

下面就是我在Web.config了。

 <授权>
<让角色=公司\\ USER_1/>
<让角色=公司\\ User_2/>
<让角色=公司\\ User_3/><拒绝用户=*/>
< /授权>

=============================================== =====================================
下面是我在标签

 <&的System.Web GT;
    <! -
            集编译调试=true以将调试
            符号插入到编译页。因为这
            影响性能,因此将该值设置为唯一的真
            在开发过程中。
         - >
    <的customErrors模式=关/>
    <编译调试=真正的>
    <&集会GT;
    <添加组件=System.Core程序,版本= 3.5.0.0,文化=中性公钥= B77A5C561934E089/>
    <添加组件=System.Data.DataSetExtensions,版本= 3.5.0.0,文化=中性公钥= B77A5C561934E089/>
    <添加组件=System.Web.Extensions程序,版本= 3.5.0.0,文化=中性公钥= 31BF3856AD364E35/>
    <添加组件=System.Xml.Linq的,版本= 3.5.0.0,文化=中性公钥= B77A5C561934E089/>
    <添加组件=System.Data.OracleClient的,版本= 2.0.0.0,文化=中性公钥= B77A5C561934E089/>
    <添加组件=System.Web.DataVisualization,版本= 3.5.0.0,文化=中性公钥= 31BF3856AD364E35/>
    <添加组件=System.Windows.Forms的,版本= 2.0.0.0,文化=中性公钥= B77A5C561934E089/>
    <添加组件=Microsoft.SqlServer.ConnectionInfo,版本= 9.0.242.0,文化=中性公钥= 89845DCD8080CC91/>
    <添加组件=Microsoft.SqlServer.Smo,版本= 9.0.242.0,文化=中性公钥= 89845DCD8080CC91/>
    <添加组件=Microsoft.SqlServer.SmoEnum,版本= 9.0.242.0,文化=中性公钥= 89845DCD8080CC91/>
    <添加组件=Microsoft.SqlServer.SqlEnum,版本= 9.0.242.0,文化=中性公钥= 89845DCD8080CC91/>< /组件>
    < /编译>
    <! -
            在<身份验证和GT;节可以配置
            所使用的安全性的认证模式的
            ASP.NET识别传入的用户。
         - >
    <身份验证模式=窗口/>    <授权>
       <让角色=公司\\ USER_1/>
       <让角色=公司\\ User_2/>
       <让角色=公司\\ User_3/>       <拒绝用户=*/>
    < /授权>    <身份冒充=真的userName =公司\\ USER_1密码=密码/>
    <! -
            在<&的customErrors GT;节可以配置
            的什么,如果/当发生未处理的错误做
            一个请求的执行过程中。特别,
            它允许开发人员配置HTML错误页
            要显示代替错误堆栈跟踪。        <的customErrors模式=仅限远程的defaultRedirect =GenericErrorPage.htm>
            <错误状态code =403重定向=NoAccess.htm/>
            <错误状态code =404重定向=FileNotFound.htm/>
        < /&的customErrors GT;
         - >
    <页面maintainScrollPositionOnPostBack =真正的>
    <控制与GT;
    <添加标签preFIX =ASP的命名空间=System.Web.UI程序组件=System.Web.Extensions程序,版本= 3.5.0.0,文化=中性公钥= 31BF3856AD364E35/>
    <添加标签preFIX =ASP的命名空间=System.Web.UI.WebControls集结号=System.Web.Extensions程序,版本= 3.5.0.0,文化=中性公钥= 31BF3856AD364E35/>
    <添加标签preFIX =ASP的命名空间=System.Web.UI.DataVisualization.Charting集结号=System.Web.DataVisualization,版本= 3.5.0.0,文化=中性公钥= 31bf3856ad364e35/&GT ;
    < /控制>
    < /页>
    <&HttpHandlers的GT;
    <清除路径=* ASMX。动词=*/>
    <添加路径=*。ASMX动词=*TYPE =System.Web.Script.Services.ScriptHandlerFactory,System.Web.Extensions程序,版本= 3.5.0.0,文化=中性公钥= 31BF3856AD364E35验证= 假/>
    <添加路径=* _ AppService.axd动词=*TYPE =System.Web.Script.Services.ScriptHandlerFactory,System.Web.Extensions程序,版本= 3.5.0.0,文化=中性公钥= 31BF3856AD364E35验证=FALSE/>
    <添加路径=的ScriptResource.axd动词=GET,HEADTYPE =System.Web.Handlers.ScriptResourceHandler,System.Web.Extensions程序,版本= 3.5.0.0,文化=中性公钥= 31BF3856AD364E35验证= 假/>
    <添加路径=ChartImg.axd动词=GET,HEAD,POSTTYPE =System.Web.UI.DataVisualization.Charting.ChartHttpHandler,System.Web.DataVisualization,版本= 3.5.0.0,文化=中立,公钥= 31bf3856ad364e35验证=FALSE/>
    < / HttpHandlers的>
    <&的HttpModules GT;
    <添加名称=ScriptModuleTYPE =System.Web.Handlers.ScriptModule,System.Web.Extensions程序,版本= 3.5.0.0,文化=中性公钥= 31BF3856AD364E35/>
    < /&的HttpModules GT;
    < /system.web>


解决方案

您可以使用位置标记来控制这种类型的东西。

在这个例子中,我给客户和管理员访问CustomersFolder目录:

 <位置路径=CustomersFolder>
<&的System.Web GT;
<授权>
<让角色=客户,管理/>
<拒绝用户=*/>
< /授权>
< /system.web>
< /地点>

和这个第二块,我则限制文件夹下访问某些文件只是管理员:

 <位置路径=CustomersFolder / SecureFile.aspx>
<&的System.Web GT;
<授权>
<让角色=管理/>
<拒绝用户=*/>
< /授权>
< /system.web>
< /地点>

我希望这样的事情会为你工作。

How do I allow access to my web application to a user, but deny them access to a specific page? I want to allow more uses to use an app I've built, but there are a couple pages I don't want them to be able to access.

Here's what I have in the Web.config now.

	<authorization>
		<allow roles="COMPANY\User_1"/>
		<allow roles="COMPANY\User_2"/>
		<allow roles="COMPANY\User_3"/>

		<deny users="*"/>
	</authorization>

==================================================================================== Here's what I have in tag

<system.web>
    	<!-- 
            Set compilation debug="true" to insert debugging 
            symbols into the compiled page. Because this 
            affects performance, set this value to true only 
            during development.
        -->
    	<customErrors mode="Off"/>
    	<compilation debug="true">
    		<assemblies>
    			<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    			<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    			<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    			<add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    			<add assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    			<add assembly="Microsoft.SqlServer.ConnectionInfo, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
    			<add assembly="Microsoft.SqlServer.Smo, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
    			<add assembly="Microsoft.SqlServer.SmoEnum, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
    			<add assembly="Microsoft.SqlServer.SqlEnum, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/></assemblies>
    	</compilation>
    	<!--
            The <authentication> section enables configuration 
            of the security authentication mode used by 
            ASP.NET to identify an incoming user. 
        -->
    	<authentication mode="Windows"/>





    <authorization>
       <allow roles="COMPANY\User_1"/>
       <allow roles="COMPANY\User_2"/>
       <allow roles="COMPANY\User_3"/>

       <deny users="*"/>
    </authorization>



    	<identity impersonate="true" userName="COMPANY\User_1" password="password"/>
    	<!--
            The <customErrors> section enables configuration 
            of what to do if/when an unhandled error occurs 
            during the execution of a request. Specifically, 
            it enables developers to configure html error pages 
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
    	<pages maintainScrollPositionOnPostBack="true">
    		<controls>
    			<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    		</controls>
    	</pages>
    	<httpHandlers>
    		<remove path="*.asmx" verb="*"/>
    		<add path="*.asmx" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
    		<add path="*_AppService.axd" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
    		<add path="ScriptResource.axd" verb="GET,HEAD" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
    		<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
    	</httpHandlers>
    	<httpModules>
    		<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    	</httpModules>
    </system.web>

解决方案

You can use location tags to control this type of thing.

In this example, I give Customers and Admins access to the CustomersFolder directory:

<location path="CustomersFolder">
	<system.web>
		<authorization>
			<allow roles="Customers, Admin"/>
			<deny users="*"/>
		</authorization>
	</system.web>
</location>

And with this second block, I then limit access to a certain file under that folder to just Admins:

<location path="CustomersFolder/SecureFile.aspx">
	<system.web>
		<authorization>
			<allow roles="Admin"/>
			<deny users="*"/>
		</authorization>
	</system.web>
</location>

Hopefully something like that will work for you.

这篇关于Asp.Net否认在某些网页上的用户访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆