简体   繁体   English

如何在C#背后的代码中获取hreflang值

[英]How to get hreflang value in code behind c#

<link rel="alternate" hreflang="zh-cn" /><br />

How to get hreflang value in code behind c#. 如何在C#背后的代码中获取hreflang值。 I tried many ways but still not working. 我尝试了许多方法,但仍然无法正常工作。

You can try this way : 您可以这样尝试:

<link rel="alternate" id="hrid" hreflang="zh-cn" />

    var v = document.getElementById("hrid").hreflang;

You need to make the <link /> tag a server-side control by adding ID and runat attributes: 您需要通过添加ID和runat属性使<link />标记成为服务器端控件:

<link id="AlternateLink" runat="server" rel="alternate" hreflang="zh-cn" />

You can retrieve the value of the hreflang attribute from your code-behind by using this code: 您可以使用以下代码从背后的代码中检索hreflang属性的值:

string hrefLangAttr = AlternateLink.Attributes["hreflang"].ToString();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM