IIS,拒绝访问静态文件;什么是错的这个例子吗? [英] IIS, denying access to static files; What is wrong with this example?

查看:131
本文介绍了IIS,拒绝访问静态文件;什么是错的这个例子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得允许在默认情况下访问,拒绝访问,除非验证在IIS中指定目录,工作的最简单的例子。当你谷歌周围,大家都说它像这样简单:

I am trying to get the simplest example of allowing access by default, denying access unless authenticated to specific directories in IIS, to work. When you Google around, everyone says it's as simple as this:

<location path="~/pages">
    <system.web>
        <authorization>
            <deny users="?"/>
        </authorization>
    </system.web>
</location>

不知何故,一直没有适合我。

Somehow it hasn't been for me.

下面是项目结构:

下面是在Web.config:

Here's the Web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
        <authentication mode="Forms">
            <forms loginUrl="~/" />
        </authentication>
        <authorization>
            <!--<deny users="*"/>-->
        </authorization>
    <compilation debug="true" targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
  </system.web>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>
    <location path="~/pages">
        <system.web>
            <authorization>
                <deny users="?"/>
            </authorization>
        </system.web>
    </location>
</configuration>

我们的目标是让所有用户访问index.html,然后拒绝访问一切都在网页上。

这是我的意见:


  • &LT;! - &LT;拒绝用户=*/&GT; - 方式&gt; 工作时取消注释

  • 这根本不​​无&LT工作;模块runAllManagedModulesForAllRequests =真/&GT; 。删除此,拒绝不任何地方工作。

  • 拒绝&LT;位置路径=〜/页&GT; 不起作用。设置路径或页/ secure.html 页面或〜/页/安全。 HTML 也不起作用。

  • <!--<deny users="*"/>--> works when un-commented.
  • It doesn't work at all without <modules runAllManagedModulesForAllRequests="true" />. Remove this, deny doesn't work anywhere.
  • The deny in <location path="~/pages"> doesn't work. Setting the path to pages or pages/secure.html or ~/pages/secure.html also doesn't work.

这里有什么问题吗?

推荐答案

它不喜欢的路径〜/页。对我来说,以下工作

it doesn't like the path "~/pages" . The following works for me

<configuration>
    <system.web>
        <authentication mode="Forms"/>
        <compilation debug="true" targetFramework="4.5.1" />
        <httpRuntime targetFramework="4.5.1" />
    </system.web>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"></modules>
    </system.webServer>

    <!-- note the change below -->
    <location path="pages" >
        <system.web>
            <authorization>
                <deny users="?"/>
            </authorization>
        </system.web>
    </location>
</configuration>

这篇关于IIS,拒绝访问静态文件;什么是错的这个例子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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