通过ASP.NET运行时将IIS7配置为服务器静态内容 [英] Configure IIS7 to server static content through ASP.NET Runtime

查看:146
本文介绍了通过ASP.NET运行时将IIS7配置为服务器静态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了一个低,仍然找不到一个明确的答案。

I searched high an low and still cannot find a definite answer.

如何在IIS中配置IIS 7.0或Web应用程序,以便ASP.NET运行时将处理所有请求 - 包括静态文件,如 * .js * .gif 等等?

How do I configure IIS 7.0 or a Web Application in IIS so that ASP.NET Runtime will handle all requests -- including ones to static files like *.js, *.gif, etc?

我要做的是如下。

我们有一种SaaSy网站,我们可以为每个客户品牌化。 品牌意味着开发自定义母版页并使用一堆 *。css 和其他图片。

We have kind of SaaSy site, which we can "brand" for every customer. "Branding" means developing a custom master page and using a bunch of *.css and other images.

相当当然,我正在使用 VirtualPathProvider ,其运作方式如下:

Quite naturally, I'm using VirtualPathProvider, which operates like this:

public override System.Web.Hosting.VirtualFile GetFile(string virtualPath)
{
    if(PhysicalFileExists(virtualPath))
    {
        var virtualFile = base.GetFile(virtualPath);
        return virtualFile;
    }

    if(VirtualFileExists(virtualPath))
    {
        var brandedVirtualPath = GetBrandedVirtualPath(virtualPath);
        var absolutePath = HttpContext.Current.Server.MapPath(brandedVirtualPath);

        Trace.WriteLine(string.Format("Serving '{0}' from '{1}'", 
            brandedVirtualPath, absolutePath), "BrandingAwareVirtualPathProvider");

        var virtualFile = new VirtualFile(brandedVirtualPath, absolutePath);
        return virtualFile;    
    }

    return null;
}

基本思路如下:我们有我们的webapp中的品牌文件夹,其中包含每个品牌的文件夹,其中品牌等于主机名。也就是说,对 http://foo.example.com/ 的请求应该使用来自 branding / foo_example_com 的静态文件,而 http://bar.example.com/ 应使用 branding / bar_example_com 中的内容。

The basic idea is as follows: we have a branding folder inside our webapp, which in turn contains folders for each "brand", with "brand" being equal to host name. That is, requests to http://foo.example.com/ should use static files from branding/foo_example_com, whereas http://bar.example.com/ should use content from branding/bar_example_com.

现在我想让IIS做的是将所有静态文件请求转发到 StaticFileHandler ,然后使用整个基础设施并提供正确的文件。但是,尽我所能,我无法配置IIS来执行此操作。

Now what I want IIS to do is to forward all requests to static files to StaticFileHandler, which would then use this whole "infrastructure" and serve correct files. However, try as I might, I cannot configure IIS to do this.

推荐答案

如果应用程序池的<$> II7已经这样做了c $ c>托管管道模式设置为集成这是默认值。在集成模式下,ASP.NET处理所有请求,包括静态对象的请求。

II7 already does that if the application pool's Managed Pipeline Mode is set to Integrated which is the default. In Integrated mode, ASP.NET handles all requests including those for static objects.

如果必须将应用程序池保留在经典模式

If you have to leave your application pool in Classic Mode then you need to use the same techniques you would use in IIS 6 to explicitly create handlers for the various static extensions.

基于附加信息评论:我认为你缺少的部分是创建一个 HttpHandler 来处理其他扩展(.js,.css等)。如果没有这个,那么ASP.NET将使用这些类型文件的默认处理。您将在web.config中创建对处理程序的引用。 本文是为静态文件创建HttpHandler的示例。

Additional Information Based on Comments: I think your missing piece is creating an HttpHandler to handle the other extensions (.js, .css, etc.). Without this, then ASP.NET will use the default handling for these types of files. You would create a reference to you handler in your web.config. This article is an example of creating an HttpHandler for static files.

这篇关于通过ASP.NET运行时将IIS7配置为服务器静态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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