博客
关于我
ASP.NET MVC模式——WebPages
阅读量:469 次
发布时间:2019-03-06

本文共 1454 字,大约阅读时间需要 4 分钟。

本页面仅作测试页面处理
public class Program{  public static void Main(string[] args)  {}        }

 

WebPages

示例

123456     

Hello Web Pages

The time is @DateTime.Now

Razor

  • 一种对网页添加服务器代码的标记语法
  • 支持C#和Visual Basic

语法规则

  1. @{...}包围
  2. 行内表达式以@开头
  3. 代码以分号结尾
  4. 通过var关键字声明变量
  5. 字符串用引号包围
  6. C#对大小写敏感
  7. C#扩展名.cshtml

示例

12345678910111213
@{ var myMessage = "Hello World"; }

The value of myMessage is: @myMessage

@{var greeting = "Welcome to our site!";var weekDay = DateTime.Now.DayOfWeek;var greetingMessage = greeting + " Today is: " + weekDay;}

The greeting is: @greetingMessage

布局

内容块

通过Web Pages,可以使用@RenderPage()从不同文件导入。

内容块能够输入到网页中任意位置,可包含文本标记代码

示例

12345678@RenderPage("header.cshtml")

Hello Web Pages

This is a paragraph

@RenderPage("footer.cshtml")

使用布局页面

布局页类似于普通网页。但在引用内容页的位置调用。

每个内容页面必须以Layout开头。

123456789@{Layout="Layout.cshtml";}

Welcome to W3Schools

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.

在ASP.NET中,名称以下划线开头的文件无法通过 web 来浏览。

如果您希望禁止用户查看内容块或布局文件,请对文件重新命名:

_header.cshtml
_footer.cshtml
_Layout.cshtml

隐藏敏感信息

在ASP.NET中,隐藏敏感信息(数据库密码、电邮密码等)的常用方法是把这些信息保存在名为 “_AppStart” 的独立文件中。

1234567@{WebMail.SmtpServer = "mailserver.example.com";WebMail.EnableSsl = true;WebMail.UserName = "username@example.com";WebMail.Password = "your-password";WebMail.From = "your-name-here@example.com";}

 

转载地址:http://mlwfz.baihongyu.com/

你可能感兴趣的文章
memcached高速缓存学习笔记001---memcached介绍和安装以及基本使用
查看>>
memcached高速缓存学习笔记003---利用JAVA程序操作memcached crud操作
查看>>
Memcached:Node.js 高性能缓存解决方案
查看>>
memcache、redis原理对比
查看>>
memset初始化高维数组为-1/0
查看>>
Metasploit CGI网关接口渗透测试实战
查看>>
Metasploit Web服务器渗透测试实战
查看>>
Moment.js常见用法总结
查看>>
MongoDB出现Error parsing command line: unrecognised option ‘--fork‘ 的解决方法
查看>>
mxGraph改变图形大小重置overlay位置
查看>>
MongoDB学习笔记(8)--索引及优化索引
查看>>
MQTT工作笔记0009---订阅主题和订阅确认
查看>>
ms sql server 2008 sp2更新异常
查看>>
MS UC 2013-0-Prepare Tool
查看>>
msbuild发布web应用程序
查看>>
MSB与LSB
查看>>
MSCRM调用外部JS文件
查看>>
MSCRM调用外部JS文件
查看>>
MSEdgeDriver (Chromium) 不适用于版本 >= 79.0.313 (Canary)
查看>>
MsEdgeTTS开源项目使用教程
查看>>