Why does a trailing slash get automatically added to meta elements in an ASP.NET master page, but not when the meta elements appear in an ASPX page?

kgcode 5 Reputation points
2024-01-23T21:00:20.5966667+00:00

Using Visual Studio 2022 to develop an ASP.NET web site a master page, when a meta element is part of a master page, a trailing slash gets automatically added to the element by the time the page is served. For example, if this appears in the master page:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

it will appear to the browser (sources view, not element view) as:

<meta name="viewport" content="width=device-width, initial-scale=1.0" />

When the meta element is part of an ASPX page (whether based on that master page or not), the trailing slash is not automatically added to the element. For example, if this appears in the ASPX page:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

it will appear the same, without any additional trailing slash in the browser (sources view):

<meta name="viewport" content="width=device-width, initial-scale=1.0">

So, if the element is in the master page without a trailing slash, the trailing slash gets added automatically to the element by the time the browser sees it. If the element is in an ASPX page without a trailing slash, no trailing slash is automatically added. This is reproducible using the local "view page in browser" in Visual Studio, using either Edge or Chrome browsers, all with the latest updates. Why does a trailing slash get automatically added to meta elements appearing in an ASP.NET master page, but not when the meta elements appear in an ASPX page? Is there some master page setting in Visual Studio 2022 that controls whether trailing slashes are added? If so, where would I find it?

Developer technologies ASP.NET Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2024-01-23T22:51:44.2633333+00:00

    There is no setting controlling this that I'm aware of. It is most likely a result of how the data is being written out. Meta tags are self-closing and shouldn't need the />. If you put one in then the browser will ignore it. There are some issues if you're targeting HTML5 vs XHTML though as XHTML would require them to be closed but HTML5 does not, IIRC.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.