When I create any views in my application in ASP.NET then I see that
<head runat="server">
If I change it to
<head>
what is difference between these two conditions?
When I create any views in my application in ASP.NET then I see that
<head runat="server">
If I change it to
<head>
what is difference between these two conditions?
If you define the head tag with the runat attribute set to "server", the value of Title attribute in the page declaration will be shown.
Let's assume you've defined a page with the following declaration on top of the code:
MyPage.aspx:
<%@ Page title="My Website"...
Let's also assume that the master page's head tag is defined as follows:
Site.Master:
<head runat="server"></head>
Then the resulting markup will look like the following:
<head><title>My Website</title></head>
If you define the head tag without the runat attribute set, the title defined by the Title attribute just won't be displayed, and you have to set the title directly in the markup:
<head><title>My Website (Title has been set manually)</title></head>
Update:
If you create a new MVC project with Visual Studio, the master page will contain an asp:ContentPlaceHolder within the title tag as default:
<head runat="server">
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
</head>
The asp:ContentPlaceHolder's content will override the value of the Title attribute you've set in the page declaration, as correctly noted in a comment to this answer by the user Yngvebn
If you have a tag within the section with a relative url, it fixes up the src path. For example, consider that you may have the head section within a master page which responds to the following URLs.
/foo /foo/bar /foo/bar/baz
But your script src is "../scripts/script.js"
That relative path is only going to be valid for one of those requests. But by using head runat="server", ASP.NET fixes it so it works for all of them.