.net - ASP.NET 的自定义文件扩展名 - 需要帮助!

标签 .net asp.net apache httphandler file-extension

我让 modaspdotnet 在我的 Apache 2.2 服务器上运行,因此它可以很好地运行 ASP.NET 和 MySQL。

但是,我想做的是提供具有其他扩展名的内容,而不仅仅是默认的 .aspx,例如myfile.custom 扩展名。

在 Apache 中,我相信它是通过 .htaccess 完成的,但在 ASP.NET 中它是通过 web.config 完成的。

这是我的 web.config 文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
  </system.web>
    <system.webServer>
        <staticContent>
            <mimeMap fileExtension=".testing1" mimeType="application/x-asp-net " />
        </staticContent>
    </system.webServer>

</configuration>

它确实有效,但 ASP.NET 代码无法正确呈现 - 我希望能够使用任何自定义扩展来运行 ASP.NET 代码。

已安装 IIS 和 NET 3.5。

我不想运行完整的 IIS 服务器,但我正在做的项目确实需要 ASP.NET,因此是 Apache 的 modaspdotnet 附加组件。

这是我的 httpd.conf 的最后一行,表示安装 modaspdotnet:
    LoadModule aspdotnet_module modules/mod_aspdotnet.so

# Use the asp.net handler for all common ASP.NET file types
AddHandler asp.net asax ascx ashx asmx aspx axd config cs csproj \
                   licx rem resources resx soap vb vbproj vsdisco webinfo 
<IfModule mod_aspdotnet.cpp> 
  # For all virtual ASP.NET webs, we need the aspnet_client files
  # to serve the client-side helper scripts.
  AliasMatch /aspnet_client/system_web/(\d+)_(\d+)_(\d+)_(\d+)/(.*) "C:/Windows/Microsoft.NET/Framework/v$1.$2.$3/ASP.NETClientFiles/$4"
  <Directory "C:/Windows/Microsoft.NET/Framework/v*/ASP.NETClientFiles">
    Options FollowSymlinks
    Order allow,deny
    Allow from all
  </Directory>
</IfModule>
#asp.net 
AddType application/x-asp-net .asp
AddType text/html .asp
AddHandler application/x-httpd-php .asp

为什么这对我不起作用,我应该怎么做才能解决这个问题?
我环顾了网络,但找不到太多......有什么想法吗?

最佳答案

简单地添加 mime 类型是不够的 - 页面不会被解释,而只是流式传输到浏览器。
我对 apache 了解不多。但是通常当您想要提供普通的 aspx 页面但具有不同的扩展名时,您必须:

  • 在自定义扩展名下添加默认的 aspx httphandler,如下所示:

  •  <httpHandlers>
    ...
    <add verb="*" path="*.mycustomextension"> type="System.Web.UI.PageHandlerFactory"/>
    

  • 注册构建提供者:

  • <compilation >
          <buildProviders>
              <add extension=".mycustomextension" type="System.Web.Compilation.PageBuildProvider" /> 
          </buildProviders>
    


    尝试一下,也许这会为您指明正确的方向

    关于.net - ASP.NET 的自定义文件扩展名 - 需要帮助!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6004213/

    相关文章:

    java - Web应用程序java从文件加载资源

    .net - 递归地将字符串拆分为字符列表

    java - 什么等同于 Java 中的 .NET SortedDictionary?

    .net - 是否应该注入(inject)基础设施依赖项?

    ASP.NET 母版页和 View 状态

    asp.net - 控件的 CssClass 字段在 Init 上更改

    c# - C# 中的 C++ 样式模板,以任何方式可能吗?

    Linux 上的 Asp.net 核心 - dotnet ef 数据库更新失败并出现版本错误

    apache - 从外部访问在 VirtualBox 上运行的 CentOS 7(最小)服务器

    Apache 8.5 拒绝编码的 url