Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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
asp.net MVC3根据页面内容自动生成元关键字和描述_Asp.net_Asp.net Mvc 3_Seo_Razor - Fatal编程技术网

asp.net MVC3根据页面内容自动生成元关键字和描述

asp.net MVC3根据页面内容自动生成元关键字和描述,asp.net,asp.net-mvc-3,seo,razor,Asp.net,Asp.net Mvc 3,Seo,Razor,我正在使用razor视图引擎开发MVC3 web应用程序。我正在寻找一个解决方案,生成元关键字和描述自动在我的网页上 我已经找到了stackoverflow的解决方案,这个想法看起来不错。但既然我打算写博客等等。。。在我的网站上,我希望元关键字和描述能够根据页面内容自动生成 到目前为止,我有以下几点想法。假设当前的HTML如下所示 <html> <head> </head> <body>

我正在使用razor视图引擎开发MVC3 web应用程序。我正在寻找一个解决方案,生成元关键字和描述自动在我的网页上

我已经找到了stackoverflow的解决方案,这个想法看起来不错。但既然我打算写博客等等。。。在我的网站上,我希望元关键字和描述能够根据页面内容自动生成

到目前为止,我有以下几点想法。假设当前的HTML如下所示

   <html>
    <head>
    </head>
        <body>
            <header></header>
            <div id="container">
                <div id="sideBar"></div>
                <div id="pageHeader"></div>
                <div id="content">
                    <!--This part contains the dynamic content-->
                </div>
                <div class="clear"></div>
            </div>
            <footer></footer>
        </body>
    </html>
   <html>
    <head>
        @Html.MetaKeywords()
        @Html.MetaDescription()
    </head>
        <body>
            <header></header>
            <div id="container">
                <div id="sideBar"></div>
                <div id="pageHeader"></div>
                <div id="content">
                    <!--This part contains the dynamic content-->
                </div>
                <div class="clear"></div>
            </div>
            <footer></footer>
        </body>
    </html>

我所期望的情况如下:

   <html>
    <head>
    </head>
        <body>
            <header></header>
            <div id="container">
                <div id="sideBar"></div>
                <div id="pageHeader"></div>
                <div id="content">
                    <!--This part contains the dynamic content-->
                </div>
                <div class="clear"></div>
            </div>
            <footer></footer>
        </body>
    </html>
   <html>
    <head>
        @Html.MetaKeywords()
        @Html.MetaDescription()
    </head>
        <body>
            <header></header>
            <div id="container">
                <div id="sideBar"></div>
                <div id="pageHeader"></div>
                <div id="content">
                    <!--This part contains the dynamic content-->
                </div>
                <div class="clear"></div>
            </div>
            <footer></footer>
        </body>
    </html>

@Html.MetaKeywords()
@Html.MetaDescription()
说了这么多,我还有以下问题没有回答,希望有人能帮忙

  • 上面描述的情况,使用HTML帮助程序。这是一种基于内容在每个页面上生成关键字和描述的好方法吗
  • 如果是这样的话,有没有人有经验,或者是一个很好的例子
  • 如果没有,还有其他好的选择吗?然后在每个控制器操作上使用属性?这仍然是一个选项,但它不会根据我的页面内容生成关键字描述

  • 我希望有人能帮助我。谢谢

    如果我理解正确,您希望能够基于content div中的文本自动生成元数据吗

    我会尝试将text/html/model传递到MetaKeywords和MetaDescription函数中,并允许它们解析/分析/查找需要放入元数据中的信息

       <html>
        <head>
            @Html.MetaKeywords(Model.ContentText)
            @Html.MetaDescription(Model.ContentText)
        </head>
            <body>
                <header></header>
                <div id="container">
                    <div id="sideBar"></div>
                    <div id="pageHeader"></div>
                    <div id="content">
                        <!--This part contains the dynamic content-->
                    </div>
                    <div class="clear"></div>
                </div>
                <footer></footer>
            </body>
        </html>
    
    
    @MetaKeywords(Model.ContentText)
    @MetaDescription(Model.ContentText)
    
    您应该了解,生成页面内容是操作处理的最后一个阶段,它直接执行到HttpContextBase。响应和一般情况下,服务器可能永远不会缓冲整个内容,它可能会由于生成而发送到客户端


    您可以按此处所述全局注册过滤器,这样就不需要在每个操作方法上添加属性。

    在_layout.cshtml上,您可以在标题部分添加@Rendersection(“header”,false)!!暂时是假的。 稍后,您必须将其更改为true或删除必需的属性

    在您现在可以使用的每个页面上

    @section header{
    <meta name="Author" content="1SeoAdvies.nl" />;
    
    Here you add every desired meta tag.
    
    }
    
    @节头{
    ;
    在这里,您可以添加每个所需的元标记。
    }
    

    注意,在布局页面的标题部分没有元标记。

    使用动作过滤器效果很好!我会尝试一下,然后告诉你。最后我选择使用Xiconia的解决方案。这对我来说更方便,因为我总是在我的网站上有一些静态html页面,在那里我想确定我自己的关键字和描述。这个解决方案对我来说已经足够了。谢谢你的回答,直截了当,非常简单的解决方案,我一定会记住的。将尝试前面提到的解决方案,我认为这将减少视图的重量,加快加载速度,因为应用程序在数据返回到视图之前处理元数据的创建。这肯定会加快视图的创建速度,但很可能会花费更多的时间在操作上。您可以缓存整个视图,或者不使用Html.MetaKeyworks(…)方法,而是使用元数据调用Html.Action,缓存它,并根据参数进行更改。这样,您的页面将不会被缓存,但您的元数据将被缓存(这可能没有评论或论坛帖子那么重要)。