Pregunta

When using Macro caching, you can cache it by QueryString parameter, eg.

<umbraco:Macro Alias="TestMacro" runat="server" TestParam="[@MyQueryStringKey]" />

How do you cache by domain name?

I tried this but it doesn't work:

<umbraco:Macro Alias="TestMacro" runat="server" Domain='<%=Request["SERVER_NAME"]%>' />

The website is using Umbraco 4.7.

¿Fue útil?

Solución

One way would be to use a rewrite rule to add the domain name into the query string. This part of the query string would not be visible to users of the sites. After the domain name is in the query string you can just use the macro caching by query string parameter technique as usual.

Here is an example using the IIS URL Rewrite Module.

<system.webServer>
    <rewrite>
        <rules>
            <rule name="Append domain to query string" stopProcessing="false">
                <match url=".*" />
                <action type="Rewrite" url="{R:0}?currentDomain={HTTP_HOST}" appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

However, doing this may have unintended side-effects. In particular, if there are any places where you are building out a url back to the same page with the query string parameters changed (pagination, sorting, filtering, etc), you will need to take care to not include the currentDomain parameter, otherwise it will become visible to the user. This might not be an issue for you, but I have seen places where it would be.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top