Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Url rewriting 如何使Kentico将URL视为文件夹不存在';根本不存在?_Url Rewriting_Kentico - Fatal编程技术网

Url rewriting 如何使Kentico将URL视为文件夹不存在';根本不存在?

Url rewriting 如何使Kentico将URL视为文件夹不存在';根本不存在?,url-rewriting,kentico,Url Rewriting,Kentico,所以我的内容结构是根->文件夹->内容页。它的自然URL是/foldername/pagename,我正试图弄清楚如何使它总是/pagename 我可以将/pagename重定向到/foldername/pagename,但它仍然在地址栏中显示为后者。我在web.config中乱搞URL重写,我有以下几点: <rule name="Content" stopProcessing="true"> <match url="^Content/(.*)" /> &

所以我的内容结构是
根->文件夹->内容页
。它的自然URL是
/foldername/pagename
,我正试图弄清楚如何使它总是
/pagename

我可以将
/pagename
重定向到
/foldername/pagename
,但它仍然在地址栏中显示为后者。我在web.config中乱搞URL重写,我有以下几点:

<rule name="Content" stopProcessing="true">
    <match url="^Content/(.*)" />
    <action type="Rewrite" url="/{R:1}" />
</rule>


但它似乎没有任何作用。你知道我如何设置我的Kentico站点,使其将URL当作根本不存在的URL吗?

有两种方法可以实现这一点

  • 手动设置页面上的URL路径。在Pages应用程序中,打开页面,然后单击URL选项卡。用路径填充“路径或模式”字段,例如
    /pagename

  • 如果您对手动设置URL路径不满意,请创建一个,以便在文档创建(或者更新文档)时设置正确的URL路径。下面是一个例子:

    [程序集:注册表模块(typeof(PagePathModule))]
    公共类PagePathModule:模块
    {
    公共PagePathModule():基(“PagePathModule”){}
    受保护的覆盖void OnInit()
    {
    DocumentEvents.Insert.After+=DocumentInsertAfter;
    }
    私有静态void DocumentInsertAfter(对象发送方,DocumentEventArgs e)
    {
    var node=e.node;//所创建文档的树节点
    var urlPath=“/”+node.DocumentName;//使用文档名作为路径
    node.DocumentUseNamePathForUrlPath=false;//确保使用自定义URL路径
    node.DocumentUrlPath=TreePathUtils.GetSafeUrlPath(urlPath,node.NodeSiteName);//设置文档URL路径
    node.Update();
    }
    }
    
    您应该确保从路径中删除不必要的字符


    • 实现这一点的两种方法

      • 手动设置页面上的URL路径。在Pages应用程序中,打开页面,然后单击URL选项卡。用路径填充“路径或模式”字段,例如
        /pagename

      • 如果您对手动设置URL路径不满意,请创建一个,以便在文档创建(或者更新文档)时设置正确的URL路径。下面是一个例子:

        [程序集:注册表模块(typeof(PagePathModule))]
        公共类PagePathModule:模块
        {
        公共PagePathModule():基(“PagePathModule”){}
        受保护的覆盖void OnInit()
        {
        DocumentEvents.Insert.After+=DocumentInsertAfter;
        }
        私有静态void DocumentInsertAfter(对象发送方,DocumentEventArgs e)
        {
        var node=e.node;//所创建文档的树节点
        var urlPath=“/”+node.DocumentName;//使用文档名作为路径
        node.DocumentUseNamePathForUrlPath=false;//确保使用自定义URL路径
        node.DocumentUrlPath=TreePathUtils.GetSafeUrlPath(urlPath,node.NodeSiteName);//设置文档URL路径
        node.Update();
        }
        }
        
        您应该确保从路径中删除不必要的字符


      似乎无法运行代码。我需要在Kentico的某个地方注册才能使用它吗?我假设App_数据文件夹中的类是自动处理的。没有关系!刚刚找到提到它需要在Web应用程序的旧应用程序代码文件夹中的部分。现在开始工作了,谢谢!似乎无法运行代码。我需要在Kentico的某个地方注册才能使用它吗?我假设App_数据文件夹中的类是自动处理的。没有关系!刚刚找到提到它需要在Web应用程序的旧应用程序代码文件夹中的部分。现在开始工作了,谢谢!