Can i add a footer to multiple .net applications?

2019-09-05 04:59发布

问题:

I would like to implement google analitycs on a website that's a mix of classic asp and various .net applications. All classic ASP pages share a footer.inc file, so that's a no brainer. However, the .net pages don't share anything, and sometimes don't even use master pages. Is there a way i could compile a DLL, drop it into the GAC and just reference it in web.config?

Thanks!

回答1:

You can make an IHttpModule, in which you add a filter to the response stream.

In that filter, you can look for the closing body tag, (for instance), and add whatever markup you need, there. Here is an article with details on the approach: HttpFilters.

When you have the module ready, you can put the module in GAC, and reference it in the web.config for each of your applications. If you need on every .NET application on the server, you could also put it in the machine-wide web.config file (to save you the trouble of editing all the web.configs). This file is found in C:\Windows\System\Microsoft.NET\Framework\<version>\CONFIG