代码之家  ›  专栏  ›  技术社区  ›  Chris

在DotnetNuke站点中,如何绕过404错误?

  •  0
  • Chris  · 技术社区  · 6 年前

    我有一个网站——example.com。它有静态页面——example.com/signup、example.com/faq等。

    但是,我希望能够有“example.com/some search term”。当然,没有“某个搜索词”页面。

    我尝试在404错误页面上安装一个自定义模块,该模块将获取查询字符串并根据该搜索条件显示一些信息。但是,我仍然得到一个404错误“http404:not found-服务器没有找到与请求的URI(统一资源标识符)匹配的任何内容。 获取- http://example.com/some-search-term ”页面空白。

    当404页面被触发时,我可以调试我的模块,看到一切正常,但最终的结果没有显示出来。

    有什么想法吗?

    2 回复  |  直到 6 年前
        1
  •  1
  •   ajwaka    6 年前

    Web.config

    <rewrite>
      <rewriteMaps configSource="fmrewrites.config" />
      <rules configSource="fmrules.config" />
    </rewrite>
    

    fmrewrites.congig

    <?xml version="1.0" encoding="utf-8"?>
    <rewriteMaps>
      <rewriteMap name="FmRedirects">
        <add key="www.siteexample.com/," value="https://www.siteexample.com/" />
      </rewriteMap>
    </rewriteMaps>
    

    fmrules.config

    <?xml version="1.0" encoding="utf-8"?>
    <rules>
        <clear />
        <rule name="FmRewrites" stopProcessing="true">
            <match url=".*" />
            <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
                <add input="{FmRedirects:{HTTP_HOST}{REQUEST_URI}}" pattern="(.+)" ignoreCase="true" />
            </conditions>
            <action type="Redirect" url="{C:1}" appendQueryString="false" />
        </rule>
    </rules>
    

    via MS Docs

        2
  •  0
  •   Chris    6 年前

            _rcode = Response.StatusCode;
            if (_rcode == 404) //we're on our 404 page
            {
                Response.Clear();
                Server.ClearError();
            }