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.
Server.MapPath()
onHttpRequest.Url.AbsolutePath
to get the physical pathHere is a handler (simplified) that I use routinely to server alternate files for different domains:
Now, you simple need to have alternate files in the same directories. E.g:
/Images/logo.jpg
/Images/v2.logo.jpg
/Styles/mystyle.css
/Styles/v2.mystyle.css
I hope this helps :)
I wouldn't recommend using
httpModule
as it will be called upon for each and every request which might deteriorate performance. Whereas, you can usehttpHandlers
to handle only specific paths. Therefore, my vote would be to usehttpHandlers
.But there is a glitch. By default, IIS 6 does not pass requests for non ASP.Net extension (read extensions other than .aspx, .ashx, .axd and all that) to ASP.Net by default.
Therefore, you need to add ISAPI module for CSS extension to pass the request to aspnet_isapi.dll (you can find the complete path from .aspx extension handler).
This link might help in setting up ISAPI module.
Once ASP.Net has started handling
.CSS
extension, write ahttpHandler
with your logic and add the following line underhttphandlers
section inweb.config
fileSay your httpHandler is
CSSHttpHandler
then the code would be something like this.Hope this helps.
Maybe you can add a HTTP module on old domain and check if the request.UrlReferrer is search results page from new domain and then replace links to old style-sheet in generated output.
I do something somewhat similar for files served up by our content management system. If a http handler is turned on, it inspects the filename and path to see if the user has access to the resource. If the user does, it streams the file, otherwise it returns a 401 not authorized.
I don't see why you couldn't use a handler to jump into the pipeline for the css file, check the host name, and stream out the other css file instead (if applicable). This is straightforward in IIS7 with an integrated pipeline (you didn't specify), but is also possible in IIS6 if you let a css extension be processed by .net.
Let me know if you're interested in this approach and I'll track down some code.
Edit - Here's some code
This is not exactly what you're looking for, but you may be able to get some ideas.
NOTE: This is in IIS7 with an integrated pipeline, so in IIS6 you'll have to make a change so that .css files are handled by the .net process.
And the web.config - and again - this is IIS7 so you'll be using the
<httpHandlers/>
section under system.web section. I'm looking for any file inside the Userfiles directory, but I think you could point right to a file with this.Note:
To allow .net to handle non-.net files in IIS, you must allow the .net process to handle the processing of these files. To do this, open IIS manager, navigate to the website, and click properties. Go to the 'home directory' tab and click 'configuration.' Add a wildcard mapping, and choose the .net dll. If you're unsure, copy the link from .ascx below.
Since it's IIS6, you won't be able to use the system.webServer section above, you'll need to add http handlers the old way. This link explains it: http://msdn.microsoft.com/en-us/library/46c5ddfy.aspx
Based on the domain name, you can dynamically control the part of the page from the code behind (.vb or .cs files or even a class). This will give you control to replace the css file based on the domian name. Capture the domain name in the code and then replace the css file/link, infact the whole part in the code behind. you can do this in C# or in VB.
Yes, you should be able to use an HttpModule on your "old" application to intercept the calls to the old CSS. Based on the version of IIS you have on your server, you may need to do some configuration to make sure .NET is handling calls to .css files, otherwise your HttpModule would not be called. See this question for reference.
Once .NET is handling calls to CSS, you can dynamically switch the css dynamically in case the request is for the "old" css file.
Here's an old article (since you are on .NET 1.1) that should point you in the right direction for the implementation and the configuration of IIS: "URL Rewriting in ASP.NET". Basically what you are doing is very similar, since you are "rewriting" a specific URL (the one to your old CSS file) to point to different content.