Custom file extensions for ASP.NET - help needed!

2019-02-24 00:55发布

问题:

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?

回答1:

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