【问题标题】:How to Allow download of .cs files from asp.net website?如何允许从 asp.net 网站下载 .cs 文件?
【发布时间】:2014-05-12 14:55:43
【问题描述】:

我有一个在 godaddy 服务器上运行的网站,它有 C# 教程和相关的代码文件,扩展名为 .cs。

我想要做的是,点击下载按钮应该触发 .cs 文件的下载。 但它给了我以下错误

本地主机错误:

不提供此类页面。说明:您请求的页面类型未提供服务,因为它已被明确禁止。 扩展名“.cs”可能不正确。请查看以下网址 并确保拼写正确。请求的网址: /WebSite1/SimpleHandler.cs

请告诉我如何消除此错误。

【问题讨论】:

  • 任何你想只使用cs文件下载的特殊原因。因为它们只是与教程相关的文件,所以压缩它们然后提供下载。
  • 是的,我可以直接提供 zip 文件,但我直接提供 .cs 文件,因为搜索引擎也会抓取代码文件并对其进行索引..
  • 因此,唯一可行的方法是将扩展名从 cs 删除为纯文本文件
  • 将扩展名更改为 .txt 将导致在新窗口中打开文本文件,这很好。但我无法更改扩展名
  • 这个问题似乎是题外话,因为它是针对Webmasters

标签: c# asp.net


【解决方案1】:

您需要进行两项更改:

1) 在 IIS 全局配置文件中允许 requestFiltering

更改全局配置文件:%systemroot%\System32\inetsrv\config\applicationHost.config

<section name="requestFiltering" overrideModeDefault="Allow" />

2) 允许在站点的 web.config 中下载 .cs 文件

<system.webServer>
    <security>
      <!-- Very important, the IIS configuration must have the 
           overrideModeDefault to allow in the file  
           %systemroot%\System32\inetsrv\config\applicationHost.config -->
      <!-- section name="requestFiltering" overrideModeDefault="Allow" /> -->
      <requestFiltering>
        <fileExtensions allowUnlisted="true">
          <remove fileExtension=".cs" />
        </fileExtensions>
      </requestFiltering>
    </security>
    ...
 </system.webServer>

【讨论】:

  • overrideModeDefault="Allow" 在我的网站上的 web.config 文件中是不允许的。我可以使用 allowOverride="true" 吗?但它也显示无法识别的属性错误。
  • @user1491927 overrideModeDefault 在全局 applicationHost.config 中,而不是在站点的 web.config 中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-30
  • 1970-01-01
  • 2012-08-18
  • 2018-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多