Prerender无法使用angularjs用IIS检测令牌

时间:2019-03-09 08:09:27

标签: angularjs angular-ui-router prerender prerenderview

我正在这样使用我的Web.config

$ javac Test.java
$ javah Test
$ gcc --std=c++11 -I $JAVA_HOME/include -I $JAVA_HOME/include/linux  -fPIC -shared -o libTest.so Test.cc
$ /usr/bin/java -Djava.library.path=. Test

我正在尝试实现SEO友好和社交媒体共享的目的。

出于SEO目的,我也希望在页面视图源中呈现数据。我在这部分中努力争取页面视图源。

对于EG:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
      <httpProtocol>
            <customHeaders>
                <add name="X-Prerender-Token" value="MY TOKEN" />
            </customHeaders>
        </httpProtocol>
      <rewrite>
        <rules>
    <rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAny">
          <add input="{SERVER_PORT_SECURE}" pattern="^0$" />
        </conditions>
        <action type="Redirect" url="https://www.homes247.in/" redirectType="Permanent" />
    </rule>

    <rule name="Enforce canonical hostname" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTP_HOST}" matchType="Pattern" pattern="^www\.homes247\.in$" ignoreCase="true" negate="true" />
      </conditions>
      <action type="Redirect" url="https://www.homes247.in/{R:1}" redirectType="Permanent" />
    </rule>

    <rule name="Prerender" stopProcessing="true">
                    <match url="^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent))(.*)" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{HTTP_USER_AGENT}" pattern="baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator" />
                        <add input="{QUERY_STRING}" pattern="(.*)_escaped_fragment_(.*)" ignoreCase="false" />
                    </conditions>
                    <action type="Rewrite" url="https://service.prerender.io/https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
    </rule>


          <rule name="AngularJS Routes" stopProcessing="true">
            <match url=".*" />
            <conditions logicalGrouping="MatchAll">
              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
              <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
              <add input="{REQUEST_URI}" pattern="^/(cms)" negate="true" />
              <add input="{REQUEST_URI}" pattern="^/(crm)" negate="true" />
                  </conditions>
            <action type="Rewrite" url="/" />
         </rule>
         
</rules>
      </rewrite>
        <staticContent>
            <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
        </staticContent>
    </system.webServer>
</configuration>

我还希望页面浏览源中包含标题内容。如何在angularjs的视图源中呈现页面。

1 个答案:

答案 0 :(得分:0)

代替:

<httpProtocol>
    <customHeaders>
        <add name="X-Prerender-Token" value="MY TOKEN" />
    </customHeaders>
</httpProtocol>

您可以在里面尝试吗?

<rule name="Prerender" stopProcessing="true">
    <serverVariables>
        <set name="HTTP_X_PRERENDER_TOKEN" value="MY TOKEN" />
    </serverVariables>
    ...

您可能需要在IIS服务器中添加HTTP_X_PRERENDER_TOKEN作为允许的服务器变量,以确保通过发送。我知道您可以在IIS用户界面中设置允许的服务器变量。