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

发布于 2024-11-07 10:19:10 字数 1756 浏览 0 评论 0原文

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

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

在 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

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

I've got modaspdotnet working on my Apache 2.2 server, and as such it runs ASP.NET and MySQL pretty well.

However, what I'd like to do is serve up content with other extensions than just the default .aspx, e.g. myfile.customextension.

In Apache, I believe it's done via .htaccess, but in ASP.NET it's done via the web.config.

This is my web.config file:

<?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>

It DOES work, but the ASP.NET code doesn't render properly - and I want to be able to run ASP.NET code with any custom extension.

IIS and NET 3.5 are installed.

I don't want to run a full IIS server but do need ASP.NET for a project I'm doing, hence the modaspdotnet add-on for Apache.

This is the final line of my httpd.conf signifying the install of 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

Why is this not working for me, and what should I do to resolve this?
I had a look around the net, but couldn't find too much... any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

§对你不离不弃 2024-11-14 10:19:10

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

  1. 在自定义扩展名下添加默认的 aspx httphandler,如下所示:
 ;
...
<添加动词=“*”路径=“*.mycustomextension”>类型=“System.Web.UI.PageHandlerFactory”/>
  1. 注册构建提供者:

<前><代码><编译>

<添加扩展名=“.mycustomextension”类型=“System.Web.Compilation.PageBuildProvider”/>

尝试一下也许这会给你指明正确的方向

Simple adding mime type is not enough - page is not interepreted but simply streamed to the browser.
I don't know much about apache. But normally when you want to serve normal aspx page but with different extension you have to:

  1. Add your default aspx httphandler under custom extension like this:
 <httpHandlers>
...
<add verb="*" path="*.mycustomextension"> type="System.Web.UI.PageHandlerFactory"/>
  1. Register build provider:
<compilation >
      <buildProviders>
          <add extension=".mycustomextension" type="System.Web.Compilation.PageBuildProvider" /> 
      </buildProviders>

Try it out maybe this will point you in the right direction

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文