With Web Pages, creating a website with a consistent layout is easy.
Consistent look
On the Internet, you will find that many websites have a consistent look and feel:
Every page has the same header
Every page has the same bottom part
Every page has the same style and layout
With Web Pages, you can do this very efficiently. You can write reused content blocks (such as page headers and footers) in a separate file.
You can also use layout templates (layout files) to define a consistent layout for all pages of your site.
Content Blocks
Many websites have some content that is displayed on every page of the site (such as the page header and footer).
With Web Pages, you can use the @RenderPage() method to import content from different files.
Content blocks (from another file) can be imported anywhere in the web page. Content blocks can contain text, markup, and code just like any normal web page.
Write the common header and bottom into separate files, which will save you a lot of work. You don't have to write the same content in every page. When the content changes, you only need to modify the header or bottom file, and you will see that the corresponding content of each page in the site has been updated.
The following shows how it is rendered in code:
Example
<html> <body> @RenderPage("header.cshtml") <h1 id="Hello-nbsp-Web-nbsp-Pages">Hello Web Pages</h1> <p>This is a paragraph</p> @RenderPage("footer.cshtml") </body> </html>
Layout Page
In the previous section, you saw Now, it's very easy to display the same content in multiple web pages.
Another way to create a consistent look is to use layout pages. A layout page contains the structure of the web page, not the content. When a web page (content page) is linked to a layout page, it is displayed according to the structure of the layout page (template).
The @RenderBody() method is used in the layout page to embed the content page. Other than that, it is no different from a normal web page.
Every content page must start with a layout directive.
Here's how it renders in code:
Layout page:
<html> <body> <p>This is header text</p> @RenderBody() <p>© 2012 W3CSchool. All rights reserved.</p> </body> </html>
Any page:
@{Layout="Layout.cshtml";}<h1 id="Welcome-nbsp-to-nbsp-W-CSchool-cc">Welcome to W3CSchool.cc</h1><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laborisnisi ut aliquip ex ea commodo consequat.</p>
D.R.Y. - Don't Repeat Yourself (Don't Repeat Yourself)
With the two ASP.NET tools Content Blocks and Layout Pages, you can give your Web applications a consistent look and feel.
These two tools can save you a lot of work, you don't have to repeat the same information on every page. Centralized markup, styles, and code make your web applications easier to manage and maintain.
Prevent files from being browsed
In ASP.NET, file names starting with an underscore can prevent these files from being browsed on the Internet.
If you do not want your content blocks or layout pages to be visible to your users, you can rename these files:
_header.cshtm
_footer.cshtml
_Layout.cshtml
Hide sensitive information
In ASP.NET, the most common way to hide sensitive information (database passwords, email passwords, etc.) is to save this information In a separate file called "_AppStart".
_AppStart.cshtml @{WebMail.SmtpServer = "mailserver.example.com";WebMail.EnableSsl = true;WebMail.UserName = "username@example.com";WebMail.Password = "your-password";WebMail.From = "your-name-here@example.com";}
【Related recommendations】
1. ASP.NET free video tutorial
2. Share ASP.NET study notes (1 )--WebPages Razor
3. Share ASP.NET study notes (2)--WebPages introduction
4. A brief definition and introduction to ASP.NET
The above is the detailed content of Share ASP.NET study notes (3) WebPages layout. For more information, please follow other related articles on the PHP Chinese website!

在Windows11中,“开始”菜单经过重新设计,并具有一组简化的应用,这些应用排列在页面网格中,这与它的前身不同,后者在“开始”菜单上有文件夹、应用和组。您可以自定义“开始”菜单布局,并将其导入并导出到其他Windows设备,以根据您的喜好对其进行个性化设置。在本指南中,我们将讨论在Windows11上导入开始布局以自定义默认布局的分步说明。什么是Windows11中的Import-StartLayout?导入开始布局是Windows10和更早版本中使用的cmdlet,用于将“开始”菜单的自定

Windows11在用户体验方面带来了很多东西,但迭代并不完全防错。用户不时会遇到问题,图标定位的更改很常见。那么如何在Windows11中保存桌面布局呢?该任务有内置和第三方解决方案,无论是保存当前窗口的屏幕分辨率还是桌面图标的排列。对于桌面上有一堆图标的用户来说,这一点变得更加重要。继续阅读以了解如何在Windows11中保存桌面图标位置。为什么Windows11不保存图标布局位置?以下是Windows11不保存桌面图标布局的主要原因:对显示设置的更改:通常,当您修改显示设置时,配置的自定义

如何使用HTML和CSS创建一个响应式图片画廊展示布局在当今互联网时代,图片画廊展示是网页设计中常见的布局,可以展示各类图片和图像作品。为了让用户能够在不同设备上获得良好的浏览体验,响应式设计变得越来越重要。本文将介绍如何使用HTML和CSS创建一个响应式图片画廊展示布局,并提供具体的代码示例。步骤1:创建基本的HTML结构首先,我们需要创建一个基本的HTM

CSSPositions布局实现交互效果的创意方法随着Web技术的不断发展,用户对于网页的交互性要求也越来越高。除了简单的点击和滚动之外,设计师们也开始通过CSSPositions布局来实现更加丰富的交互效果。本文将介绍一些创意的方法,并给出具体的代码示例。StickySidebar(吸顶侧边栏)吸顶侧边栏是指在页面滚动时,侧边栏能够“吸附”在页面顶部
![古吉拉特语印度语输入 3 在 Windows 11 中不起作用 [修复]](https://img.php.cn/upload/article/000/000/164/168915871396627.png)
古吉拉特语印度语输入3是一种键盘布局,允许您输入古吉拉特语,我们的一些读者抱怨它在Windows11中不起作用。当然,在操作系统上,您可以创建自定义键盘,但使用特定于语言的布局通常会使用户体验更加愉快。因此,让我们帮助您解决PC上的此问题。为什么古吉拉特语印度语输入3不起作用?古吉拉特语印度语输入3属于MicrosoftIME(输入法编辑器),可与英语QWERTY键盘配合使用。根据用户体验,我们收集到以下主要原因:未安装键盘布局。您的键盘布局未启用。键盘布局已损坏。计算机的驱动程序有问题。您可以

HTML教程:如何使用Flexbox进行平均分配布局引言:在网页设计中,经常需要对元素进行布局。传统的布局方法存在一些局限性,而Flexbox(弹性盒子布局)是一种能够提供更灵活、更强大的布局方式。本文将介绍如何使用Flexbox来实现平均分配布局,同时给出具体的代码示例。一、Flexbox简介Flexbox是CSS3中引入的一种弹性盒子布局模型,它可以让元

float布局会引起有清除浮动问题、元素重叠问题、文字环绕问题和响应式布局问题等。详细介绍:1、清除浮动问题,当使用float布局时,浮动元素会脱离文档流,这可能导致父容器无法正确地包裹浮动元素,这种情况下,父容器的高度会塌陷,导致布局混乱;2、元素重叠问题,当多个元素使用float布局时,它们可能会发生重叠的情况,这是因为浮动元素不再占据正常的文档流位置等等。

float布局的缺点有导致元素脱离文档流、手动清除浮动、对于垂直居中和等高布局不友好、对于多列布局的支持有限、处理浮动元素高度不一致时可能会出现问题等。详细介绍:1、导致元素脱离文档流,当元素浮动时,它会脱离正常的文档流,这意味着其他元素可能会占据它原本应该占据的位置,这可能导致布局的混乱和不可预测性,特别是在处理响应式布局时更为明显;2、手动清除浮动,当一个元素浮动时等等。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools
