You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Splitting the new HTML escaping functionality into ToHtmlEscapedString().
* A new ToString() overload that accepts a JsonSerializerSettings instance.
Schema.org objects turned into strongly typed C# POCO classes for use in .NET. All classes can be serialized into JSON/JSON-LD and XML, typically used to represent structured data in the `head` section of `html` page.
4
4
@@ -16,7 +16,7 @@ var jsonLd = website.ToString();
16
16
17
17
The code above outputs the following JSON-LD:
18
18
19
-
```JSONLD
19
+
```JSON
20
20
{
21
21
"@context":"http://schema.org",
22
22
"@type":"WebSite",
@@ -26,6 +26,8 @@ The code above outputs the following JSON-LD:
26
26
}
27
27
```
28
28
29
+
If writing the result into a `<script>` element, be sure to use the `.ToHtmlEscapedString()` method instead to avoid exposing your website to a Cross-Site Scripting attack. See the [example below](#important-security-notice).
30
+
29
31
## What is Schema.org?
30
32
31
33
[schema.org](https://schema.org) defines a set of standard classes and their properties for objects and services in the real world. This machine readable format is a common standard used across the web for describing things.
@@ -56,6 +58,17 @@ Using structured data in `html` requires the use of a `script` tag with a MIME t
56
58
</script>
57
59
```
58
60
61
+
##### Important Security Notice
62
+
When serializing the result for a website's `<script>` tag, you should use the alternate `.ToHtmlEscapedString()` to avoid exposing yourself to a Cross-Site Scripting (XSS) vulnerability if some of the properties in your schema have been set from untrusted sources.
63
+
Usage in an ASP.NET MVC project might look like this:
64
+
65
+
```HTML
66
+
<scripttype="application/ld+json">
67
+
@Html.Raw(Model.Schema.ToHtmlEscapedString())
68
+
</script>
69
+
```
70
+
71
+
59
72
#### Windows UWP Sharing
60
73
61
74
Windows UWP apps let you share data using schema.org classes. [Here](https://docs.microsoft.com/en-us/uwp/schemas/appxpackage/appxmanifestschema/element-sharetarget) is an example showing how to share metadata about a book.
Copy file name to clipboardExpand all lines: Tests/Schema.NET.Test/ProductTest.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ public class ProductTest
44
44
"\"@context\":\"http://schema.org\","+
45
45
"\"@type\":\"Product\","+
46
46
"\"name\":\"Executive Anvil\","+
47
-
"\"description\":\"Sleeker than ACME\\u0027s Classic Anvil, the Executive Anvil is perfect for the business traveller looking for something to drop from a height.\","+
47
+
"\"description\":\"Sleeker than ACME's Classic Anvil, the Executive Anvil is perfect for the business traveller looking for something to drop from a height.\","+
0 commit comments