Can .NET intercept and change css files?

2020-03-09 18:29发布

UPDATE 1:

I have now setup IIS6 so .NET can handle calls to .css files. What do I have to do now to get it to change css files based on the referal url? So if the referal url is http://intranet/, it should continue calling the old style sheets. If the referal url is http://intranetv2/, it should call the new style sheet.


ORIGINAL QUESTION:

The background:

I have 2 search engines. 1 is old and the other is brand new (development stage). Search engine 1 is on domain1.com and search engine 2 is on domain2.com. Both domains are on the same server. Both search for webpages on domain1.com based on what the user enters into the search engines. The difference between the 2 search engines is that the new one is faster, produces more accurate results, and has a hugely improved user interface. Both search engines will remain live just so the users can get used to the new one in their own time, instead of just throwing them into the deep end and removing the old search engine altogether.

Anyway, enough of the background, basically, as the searchable pages reside on the old domain name with the old search engine, whereas the new search engine is on the new domain name, ...

The question:

... can I use HttpModule, or another part of .NET, or something from IIS6 even to capture the page links generated by the new search engine, and dynamically change the css file attached to the old searchable pages on the old domain?

The reason:

In effect making it look like a full brand new site, where if the search engine on the old domain is used to access the pages on the old domain, the old stylesheet is used, but if the search engine on the new domain is used to access the searchable files on the old domain name, a new stylesheet should be used to make the old pages look new. As there are lots of searchable pages, in the region of 10,000, editing each and every page to add an if statement to check the referral domain name before adding a style sheet to the pages is not a realistic option.

The environment:

The old search engine, along with the searchable pages on the old domain use .net 1.something, but the new search engine on the new domain name is using .net 3.5, and I am using vb.net for the asp.net pages. The server is a IIS6 server.

7条回答
放荡不羁爱自由
2楼-- · 2020-03-09 19:06

As I stated in my comment re: one of the answers, I think the http_referer header will point to the content page that links/imports the requested css file, not the search results page that linked to the content page. So even if search results are on http://intranetv2, Request.ServerVariables["HTTP_REFERER'] during the css file request will be http://intranet and you'll continue to get the old css file.

Seems like you'll have to figure out a way to either serve up the 10000 content pages from the new http://intranetv2 domain, or come up with a way to set a flag during the content aspx page request (maybe in global.asax Application_BeginRequest) that can be read and acted upon during the css file request (by an HttpHandler, like others have suggested).

Not sure what the appropriate signaling mechanism would be though. It needs to work per-user, not per-application as well as be available during and persist across multiple disparate file requests, and the choices are constrained by the use of .NET 1.1.

查看更多
登录 后发表回答