# EKsumic's Blog

let today = new Beginning();

Click the left button to use the catalog.

OR

# &#x27; can be used instead of \' escape characters

I have to say that I've been learning .NET Core programming for so long that I only found out today that I didn't know anything about the use of quotation marks in JavaScript.

Original:

<script>
$(document).ready(function () {$("#cancel4").click(function () {
var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL';
if (document.all) {
} else if (window.sidebar) {
} else {
alert('You can try the shortcut key' + ctrl + ' + D Add to Favorites~')
}
})
});
</script>

Change to:

<script>
$(document).ready(function () {$("#cancel4").click(function () {
var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL';
if (document.all) {
} else if (window.sidebar) {
} else {
alert('You can try the shortcut key' + ctrl + ' + D Add to Favorites~')
}
})
});
</script>

Yes, the single quotation mark inside the quotation mark must be escaped with a backslash，it's the same way I used to program in C#.

But today I just met this problem. If it wasn't for the English version of my website, I would hardly have met it.

I thought . Net core would help me to automatically escape characters when using ViewData["Title"], but it didn't.

Wait,  I found something wrong with the code.

I found that I used Html.Raw to transmit value.

Maybe Html.Raw is the cause of JavaScript errors.

OK, it's my fault.

If you use ViewData["Title"] instead of @Html.Raw(ViewData["Title"]) , the error will not occur.

At the same time, I found an interesting thing:

&#x27; replaced single quotation mark.

I mean, &#x27; replaced \'.

This is .Net core solution for escaping characters.

So,What is &#x27; ?

Unicode Hex Character Code &#x27;
' Symbol Name: Apostrophe.

This is what Google told me directly.

Original:

<script>
$(document).ready(function () {$("#cancel4").click(function () {
var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL';
if (document.all) {
} else if (window.sidebar) {
} else {
alert('You can try the shortcut key' + ctrl + ' + D Add to Favorites~')
}
})
});

</script>

.NET Core's ViewData["Title"]

<script>
$(document).ready(function () {$("#cancel4").click(function () {
var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL';
if (document.all) {
} else if (window.sidebar) {
} else {
alert('You can try the shortcut key' + ctrl + ' + D Add to Favorites~')
}
})
});
</script>

You should find that, in fact, not only &#x27;, almost all characters are encoded in hexadecimal.

In this way, we can find out how . Net core is encoded and how its lifecycle works.

It seems that . Net core passes values first, then runs JavaScript, and in order to prevent escaping characters, it uses hex directly.