2014-10-05 107 views
1

我正在使用Asp.Net Identity。我需要允许管理员和拒绝用户访问我的管理文件夹中的所有页面,所以我在该文件夹中放置了一个web.config文件。如何防止用户访问文件夹中的文件?

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
     <authorization> 
     <allow roles="Admin"/> 
     <deny users="*" /> 
     </authorization> 
    </system.web> 
</configuration> 

但任何人仍然可以访问文件夹中的所有文件。我也试着把它放到带有位置标签的主配置文件中,但没有结果。你有什么想法从哪里开始寻找问题?

更新:我发现在asp.net论坛的一个问题它解释了很多: http://forums.asp.net/t/1955560.aspx?ASP+NET+Identity+Are+web+config+files+no+longer+acting+in+the+capacity+of+a+security+guard+for+our+ASP+NET+applications+files+and+folders+ 还有一两件事要提。使用asp.net标识创建新的Web应用程序项目时。的Visual Studio 2013中设置这些参数:

<system.web> 
    <authentication mode="None"/> 
</system.web> 

<system.webServer> 
    <modules> 
    <remove name="FormsAuthenticationModule" /> 
    </modules> 
    <system.webServer> 
+0

可以编辑问题来解释你的意思是什么“它不工作”?发生了什么,你认为应该发生什么? – 2014-10-05 18:28:16

+0

更新,任何想法? – xbilek18 2014-10-06 17:11:46

回答

0

试试这个

<configuration> 

    <system.web> 

    <authentication mode="Forms"/> 
    <authorization> 
     <deny users="?"/> 

    </authorization> 
    </system.web> 

    <location path="[mymanagementfolder]"> 
    <system.web> 
     <authorization> 
     <deny users ="?" /> 
     <allow users ="*" /> 
     </authorization> 
    </system.web> 
    </location> 

</configuration> 

MSDN SOURCE

如果目录浏览在启用IIS,那么你应该把它OFF

编辑: 我想你应该启用Form/windows authentication。上面的代码是我的电脑上工作正常,因为它重定向到ReturnUrl

My Test output

+0

它不起作用。 – xbilek18 2014-10-05 14:45:42

+0

@JanBílek是在IIS中启用目录浏览? – 2014-10-05 14:51:04

+0

不,它被禁用。 – xbilek18 2014-10-05 14:52:07

0

改变你的代码** **它阻止未认证的任何用户:

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
     <authorization> 
     <allow roles="Admin"/> 
     <deny users="?" /> 
     </authorization> 
    </system.web> 
</configuration> 
+0

可悲的是,没有结果。 – xbilek18 2014-10-05 14:40:23

相关问题