SeoTags

2025-12-07 0 180

SeoTags

SeoTags生成所需的所有SEO标签,例如MetaLinkTwitter卡(Twitter :),打开图(Facebook) (OG)(OG)和JSON-LD架构(结构化数据)。

如何使用

有关更多信息,请参见https://mjebrahimi.*gi**thub.io/seotags/。

1。安装软件包

PM> Install-Package SeoTags

2。注册/配置到您的服务

您需要做的一切都是配置SeoInfo对象并将其渲染到_Layout.cshtml中。

可以通过以三种方式设置SeoInfo对象的属性来完成此配置:

  1. 使用services.Add SeoTags (seoInfo => { ... })方法在注册服务时。
  2. .cshtml视图中的Html.SetSeoInfo(seoInfo => { ... })方法(mvc或razorPages)
  3. HttpContext.SetSeoInfo(seoInfo => { ... })方法在您访问HttpContext对象的任何地方(例如,在MVC控制器/ Action或Razor-pages PageModel中)

整个网站(不是特定于某个页面)的一般选项是恒定的,例如网站标题Twitter IDFacebook IDOpenSearch URLfeeds(RSS或ATOM)等…

通常,使用services.Add SeoTags (seoInfo => { ... })方法在注册服务时设置这些值。

SeoTags(seoInfo =>
{
seoInfo.SetSiteInfo(
siteTitle: \”My Site Title\”,
siteTwitterId: \”@MySiteTwitter\”, //Optional
siteFacebookId: \”https://*faceb*ook*.com/MySite\”, //Optional
openSearchUrl: \”https://*sit*e*.com/open-search.xml\”, //Optional
robots: \”index, follow\” //Optional
);

//Optional
seoInfo.AddFeed(
title: \”Post Feeds\”,
url: \”https://site.c*om/**rss/\”,
feedType: FeedType.Rss);

//Optional
seoInfo.AddDnsPrefetch(\”https://fonts.*gstat*i*c.com/\”, \”https://www.googl*e-a**nalytics.com\”);

//Optional
seoInfo.AddPreload(new Preload(\”https://sit**e.com*/site.css\”),
new Preload(\”https://si*te.*co*m/app.js\”),
new Preload(\”https://si*te.co*m/*fonts/Font.woff2\”),
new Preload(\”https://sit*e.com**/fonts/Font_Light.woff2\”),
new Preload(\”https://s*i*t*e.com/fonts/Font_Medium.woff2\”),
new Preload(\”https://sit*e*.*com/fonts/Font_Bold.woff2\”));

//Optional
seoInfo.SetLocales(\”en_US\”);
});
//…\”>

 //Register your services
app . Services . Add SeoTags ( seoInfo =>
{
    seoInfo . SetSiteInfo (
        siteTitle : \"My Site Title\" , 
        siteTwitterId : \"@MySiteTwitter\" ,                    //Optional
        siteFacebookId : \"https://*faceb*ook*.com/MySite\" ,      //Optional
        openSearchUrl : \"https://*sit*e*.com/open-search.xml\" ,  //Optional
        robots : \"index, follow\"                             //Optional
    ) ;

    //Optional
    seoInfo . AddFeed (
        title : \"Post Feeds\" ,
        url : \"https://site.c*om/**rss/\" ,
        feedType : FeedType . Rss ) ;

    //Optional
    seoInfo . AddDnsPrefetch ( \"https://fonts.*gstat*i*c.com/\" , \"https://www.googl*e-a**nalytics.com\" ) ;

    //Optional
    seoInfo . AddPreload ( new Preload ( \"https://sit**e.com*/site.css\" ) ,
        new Preload ( \"https://si*te.*co*m/app.js\" ) ,
        new Preload ( \"https://si*te.co*m/*fonts/Font.woff2\" ) ,
        new Preload ( \"https://sit*e.com**/fonts/Font_Light.woff2\" ) ,
        new Preload ( \"https://s*i*t*e.com/fonts/Font_Medium.woff2\" ) ,
        new Preload ( \"https://sit*e*.*com/fonts/Font_Bold.woff2\" ) ) ;

    //Optional
    seoInfo . SetLocales ( \"en_US\" ) ;
} ) ;
//...

3。在您的_layout.cshtml中渲染seo标签

要渲染输出SEO标签,请致电Html. SeoTags () _Layout.cshtml中的Html. SeoTags ()方法。

此方法具有两个过载,一个具有SeoInfo参数(如果您需要传递SeoInfo对象的新任意实例),一个没有参数,可以从您以前的注册服务中检索已配置的SeoInfo对象。

@ViewData[\”Title\”] – Site Title
–>

<!– <span class=\’ notranslate keguazi>SeoTags generates all of these for you –>
@Html. SeoTags () <!– ? Add this line –>\”>

 <!DOCTYPE html >
< html lang =\" en \" >
< head >
    <!-- Remove these tags from your _Layout.cshtml
    <meta charset=\"utf-8\" />
    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />
    <title>@ViewData[\"Title\"] -  Site Title</title>
    -->

    <!-- SeoTags generates all of these for you -->
    @Html. SeoTags () <!-- ? Add this line -->

4。在您的视图/页面中设置特定的SEO信息

您可能需要为某个页面设置一些特定的SEO信息,例如页面标题页面描述页面关键字页面URL发布日期修改日期图像信息页面类型等…

为此,请在.cshtml视图中调用Html.SetSeoInfo(seoInfo => { ... })方法,以设置该页面的特定所需的SEO信息。

您可以通过调用HttpContext.SetSeoInfo(seoInfo => { ... })来执行相同的操作。您可以在访问HttpContext对象的任何地方(例如,在MVC Controller / Action或Razor-pages PageModel中)

SeoTags.TwitterCardType.SummaryLargeImage //Optional
);

seoInfo.SetArticleInfo(
authorName: \”Author Name\”,
publishDate: DateTimeOffset.Now,
modifiedDate: DateTimeOffset.Now, //Optional
authorTwitterId: \”@MyTwitterId\”, //Optional
authorFacebookId: \”https://f**a*cebook.com/MyUserId\”, //Optional
authorUrl: \”https://**github.c*om/author-profile\”, //Optional
section: \”Article Topic\” //Optional
);

//Add another RSS feed. (only for this page) (Optional)
seoInfo.AddFeed(\”Post Comments\”, \”https://*site.*c*om/post/comment/rss\”, SeoTags.FeedType.Rss);
});
}\”>

@ {
    // Remove these line from your views
    // ViewData[\"Title\"] = \"Page Title\";

    Html . SetSeoInfo ( seoInfo =>
    {
        seoInfo . SetCommonInfo (
            pageTitle : \"SEO Tags for ASP.NET Core\" ,
            description : \"SetoTags creates all SEO tags you need such as meta, link, Twitter card (twitter:), open graph (og:), and ...\" ,
            url : \"https://si*t**e.com/url/\" ,
            keywordTags : new [ ] { \"SEO\" , \"AspNetCore\" , \"MVC\" , \"RazorPages\" } , //Optional
            seeAlsoUrls : new [ ] { \"https://sit*e.*co*m/see-also-1\" , \"https://site*.c*om*/see-also-2\" }  //Optional
        ) ;

        seoInfo . SetImageInfo (
            url : \"https://site.co*m/*u*ploads/image.jpg\" ,
            width : 1280 ,                                        //Optional
            height : 720 ,                                        //Optional
            alt : \"Image alt\" ,                                   //Optional
            //mimeType: \"image/jpeg\",                           //Optional (detects from URL file extension if not set.)
            cardType : SeoTags . TwitterCardType . SummaryLargeImage //Optional
        ) ;

        seoInfo . SetArticleInfo (
            authorName : \"Author Name\" ,
            publishDate : DateTimeOffset . Now ,
            modifiedDate : DateTimeOffset . Now ,                   //Optional
            authorTwitterId : \"@MyTwitterId\" ,                    //Optional
            authorFacebookId : \"https://f**a*cebook.com/MyUserId\" ,  //Optional
            authorUrl : \"https://**github.c*om/author-profile\" ,     //Optional
            section : \"Article Topic\"                            //Optional
        ) ;

        //Add another RSS feed. (only for this page) (Optional)
        seoInfo . AddFeed ( \"Post Comments\" , \"https://*site.*c*om/post/comment/rss\" , SeoTags . FeedType . Rss ) ;
    } ) ;
}

5。完成!享受渲染输出

在浏览器中打开页面并查看源代码。

以下代码显示了此示例的渲染输出。

 <!DOCTYPE html >
< html lang =\" en \" >
< head >

< meta charset =\" utf-8 \" />
< meta http-equiv =\" Content-Type \" content =\" text/html; charset=utf-8 \" />
< meta http-equiv =\" X-UA-Compatible \" content =\" IE=edge, chrome=1 \" />
< meta name =\" viewport \" content =\" width=device-width, initial-scale=1 \" />

< link rel =\" preconnect \" href =\" https://fonts.*gstat*i*c.com/ \" crossorigin />
< link rel =\" preconnect \" href =\" https://www.googl*e-a**nalytics.com \" crossorigin />
< link rel =\" dns-prefetch \" href =\" https://fonts.*gstat*i*c.com/ \" />
< link rel =\" dns-prefetch \" href =\" https://www.googl*e-a**nalytics.com \" />
< link rel =\" preload \" as =\" style \" href =\" https://sit**e.com*/site.css \" />
< link rel =\" preload \" as =\" script \" href =\" https://si*te.*co*m/app.js \" />
< link rel =\" preload \" as =\" font \" type =\" font/woff2 \" href =\" https://si*te.co*m/*fonts/Font.woff2 \" crossorigin />
< link rel =\" preload \" as =\" font \" type =\" font/woff2 \" href =\" https://sit*e.com**/fonts/Font_Light.woff2 \" crossorigin />
< link rel =\" preload \" as =\" font \" type =\" font/woff2 \" href =\" https://s*i*t*e.com/fonts/Font_Medium.woff2 \" crossorigin />
< link rel =\" preload \" as =\" font \" type =\" font/woff2 \" href =\" https://sit*e*.*com/fonts/Font_Bold.woff2 \" crossorigin />
< link rel =\" preload \" as =\" image \" type =\" image/jpeg \" href =\" https://site.co*m/*u*ploads/image.jpg \" />

< title > SEO Tags for ASP.NET Core - My Site Title </ title >
< meta name =\" title \" content =\" SEO Tags for ASP.NET Core - My Site Title \" />
< meta name =\" description \" content =\" SetoTags Creates all SEO tags you need such as meta, link, Twitter card (twitter:), open graph (og:), and ... \" />
< meta name =\" keywords \" content =\" SEO, AspNetCore, MVC, RazorPages \" />
< meta name =\" author \" content =\" Author Name \" />
< link rel =\" author \" href =\" https://**github.c*om/author-profile \" />
< link rel =\" canonical \" href =\" https://si*t**e.com/url/ \" />
< link rel =\" application/opensearchdescription+xml \" title =\" My Site Title \" href =\" https://*sit*e*.com/open-search.xml \" />
< link rel =\" alternate \" type =\" application/rss+xml \" title =\" Post Feeds \" href =\" https://site.c*om/**rss/ \" />
< link rel =\" alternate \" type =\" application/rss+xml \" title =\" Post Comments \" href =\" https://*site.*c*om/post/comment/rss \" />

< meta name =\" twitter:card \" content =\" summary_large_image \" />
< meta name =\" twitter:title \" content =\" SEO Tags for ASP.NET Core \" />
< meta name =\" twitter:description \" content =\" SetoTags creates all SEO tags you need such as meta, link, Twitter card (twitter:), open graph (og:), and ... \" />
< meta name =\" twitter:site \" content =\" @MySiteTwitter \" />
< meta name =\" twitter:creator \" content =\" @MyTwitterId \" />
< meta name =\" twitter:image \" content =\" https://site.co*m/*u*ploads/image.jpg \" />
< meta name =\" twitter:image:width \" content =\" 1280 \" />
< meta name =\" twitter:image:height \" content =\" 720 \" />
< meta name =\" twitter:image:alt \" content =\" Image alt \" />

< meta property =\" og:type \" content =\" article \" />
< meta property =\" og:title \" content =\" SEO Tags for ASP.NET Core \" />
< meta property =\" og:description \" content =\" SetoTags creates all SEO tags you need such as meta, link, Twitter card (twitter:), open graph (og:), and ... \" />
< meta property =\" og:url \" content =\" https://si*t**e.com/url/ \" />
< meta property =\" og:site_name \" content =\" My Site Title \" />
< meta property =\" og:locale \" content =\" en_US \" />
< meta property =\" og:image \" content =\" https://site.co*m/*u*ploads/image.jpg \" />
< meta property =\" og:image:secure_url \" content =\" https://site.co*m/*u*ploads/image.jpg \" />
< meta property =\" og:image:type \" content =\" image/jpeg \" />
< meta property =\" og:image:width \" content =\" 1280 \" />
< meta property =\" og:image:height \" content =\" 720 \" />
< meta property =\" og:image:alt \" content =\" Image alt \" />
< meta property =\" article:publisher \" content =\" https://*faceb*ook*.com/MySite \" />
< meta property =\" article:author \" content =\" https://f**a*cebook.com/MyUserId \" />
< meta property =\" article:published_time \" content =\" 2021-07-03T13:34:41+00:00 \" />
< meta property =\" article:modified_time \" content =\" 2021-07-03T13:34:41+00:00 \" />
< meta property =\" article:section \" content =\" Article Topic \" />
< meta property =\" article:tag \" content =\" SEO \" />
< meta property =\" article:tag \" content =\" AspNetCore \" />
< meta property =\" article:tag \" content =\" MVC \" />
< meta property =\" article:tag \" content =\" RazorPages \" />
< meta property =\" og:see_also \" content =\" https://sit*e.*co*m/see-also-1 \" />
< meta property =\" og:see_also \" content =\" https://site*.c*om*/see-also-2 \" />

...

JSON-LD支持

SeoTags现在支持流行的JSON-LD类型,例如文章产品书籍组织网站网页等…

请参阅我们的文档以获取嵌套示例和引用示例。

笔记

  • 该软件包不会生成favicon标签。使用realfavicongoner.net生成favicon标签。
  • 仅支持ASP.NET核心(而不是遗留ASP.NET框架)

贡献

如果您找到错误或有建议或问题,请创建问题。如果您想开发此项目:

  1. 叉!
  2. 创建您的功能分支: git checkout -b my-new-feature
  3. 提交您的更改: git commit -am \'Add some feature\'
  4. 推到分支机构: git push origin my-new-feature
  5. 提交拉请请求

给星星!配x

如果您发现此存储库有用,请给它一颗星。谢谢!

执照

版权所有©2021 Mohammd Javad Ebrahimi在MIT许可下。

下载源码

通过命令行克隆项目:

git clone https://github.com/mjebrahimi/SeoTags.git

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

申明:本文由第三方发布,内容仅代表作者观点,与本网站无关。对本文以及其中全部或者部分内容的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。本网发布或转载文章出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,也不代表本网对其真实性负责。

左子网 开发教程 SeoTags https://www.zuozi.net/31829.html

libnetty
上一篇: libnetty
fast cgi proxy
下一篇: fast cgi proxy
常见问题
  • 1、自动:拍下后,点击(下载)链接即可下载;2、手动:拍下后,联系卖家发放即可或者联系官方找开发者发货。
查看详情
  • 1、源码默认交易周期:手动发货商品为1-3天,并且用户付款金额将会进入平台担保直到交易完成或者3-7天即可发放,如遇纠纷无限期延长收款金额直至纠纷解决或者退款!;
查看详情
  • 1、描述:源码描述(含标题)与实际源码不一致的(例:货不对板); 2、演示:有演示站时,与实际源码小于95%一致的(但描述中有”不保证完全一样、有变化的可能性”类似显著声明的除外); 3、发货:不发货可无理由退款; 4、安装:免费提供安装服务的源码但卖家不履行的; 5、收费:价格虚标,额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外); 6、其他:如质量方面的硬性常规问题BUG等。 注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。
查看详情
  • 1、左子会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全! 2、左子无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别; 3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外); 4、在没有”无任何正当退款依据”的前提下,商品写有”一旦售出,概不支持退款”等类似的声明,视为无效声明; 5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准); 6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在左子上所留的QQ、手机号沟通,以防对方不承认自我承诺。 7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于左子介入快速处理。
查看详情

相关文章

猜你喜欢
发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务