随笔分类 - .NET/ASP.NET MVC
摘要:引言 前文介绍了 Session-Cookie 的认证过程,简单回顾下基本步骤: 客户端(浏览器)向服务器发送用户名和密码 服务器验证通过后,创建 Session 对象,在 Session 中保存该用户相关的数据,比如用户角色、登录时间等等 服务器向用户返回这个 Session 对象的唯一标识 Se
阅读全文
摘要:1. 增加一个WebApi Controller, VS 会自动添加相关的引用,主要有System.Web.Http,System.Web.Http.WebHost,System.Net.Http 2. 在App_Start 下创建 WebApiConfig.cs 并注册路由 using Syste
阅读全文
摘要:关于视图的一些一些一些 一、Action指定使用视图public ActionResult Add(string txtName, string txtContent) { return View("Index"); return Vi...
阅读全文
摘要:mvc使用Area分区开发后,存在不同Area之间的跳转,需要为每个区间添加Area规则,如下:按 Ctrl+C 复制代码using System.Web.Mvc;namespace web.Areas.FrameSet{ public class FrameSetAreaRegistrati...
阅读全文
摘要:在MVC里从Controller发送一段带有HTML的文字到View视图时,MVC是会将这段代码进行转码的。 一、使用MvcHtmlString转HTML转码 如果想不让这段文字进行转码,以HTML的编码显示出来,可以使用MvcHtmlString。看一下下面这个DEMO。 1.Contr...
阅读全文
摘要:上传文件是一项基本功能,一定要了解的。先来看一下使用ASP.NET MVC实现简单的上传。一、简单的例子 Controller的例子 public ActionResult UploadDemo() { return View(); ...
阅读全文
摘要:ActionFilter是穿插在Action执行过程,在Action执行前后提供扩展的功能。ActionFilter用途非常的广,用在页面压缩、缓存、错误处理,登陆验证。 ActionFilter的实现需要继承自ActionFilterAttribute抽象类,并且覆盖需要使用的方法。 Ac...
阅读全文
摘要:UrlHelper提供了四个非常常用的四个方法 1.Action方法通过提供Controller,Action和各种参数生成一个URL, 2.Content方法是将一个虚拟的,相对的路径转换到应用程序的绝对路径, 3.Encode方法是对URL地址进行加密,与Server.Encode方法...
阅读全文
摘要:在ASP.NET MVC框架中没有了自己的控件,页面显示完全就回到了写html代码的年代。还好在asp.net mvc框架中也有自带的HtmlHelper和UrlHelper两个帮助类。另外在MvcContrib扩展项目中也有扩展一些帮助类,这样我们就不光只能使用完整的html来编写了需要显示的...
阅读全文
摘要:ASP.NET MVC的数据验证机制,比起ASP.NET WEBFORM那种高效很多。下面记录以下两个示例,以便日后方便查阅。 方式一:在Controller里通过AddModelError方法返回错误的验证信息,看一下代码示例: Controller里的,注意看一下,他Add的时候提交是H...
阅读全文
摘要:ASP.NET MVC中进行分页的方式有多种,在NuGet上有提供使用PagedList、PagedList.Mvc进行分页。 1. 通过NuGet引用PagedList.Mvc 在安装引用PagedList.Mvc的同时会安装引用PagedList。 1.看一下Controller页面的...
阅读全文
摘要:用习惯了ADO.NET的方式去访问数据库,虽然ADO.NET写的代码没有EF简洁,可是也并不麻烦。而且EF在进行多表查询的那种方式是,EF需要先去数据库里定义外键,再进去一次代码生成,然后才能用INCLUDE方法进行多表关联查询。我不太喜欢那样,还不如老老实实写做SQL语句。 所以ADO.NE...
阅读全文
摘要:EF是在ADO.NET的基础上做进一步封装,以后如果做新的项目我可能会考虑不用ADO.NET,而用EF。 其实很久以前我就接触过EF,可是太久没用,有些忘记了,前几天重温,也做了一点笔记。记录如下: 1.怎么创建EF不说了,看一下创建EF后,打开EF的XML文件是怎样的。 首先...
阅读全文
摘要:IIS6.01. 安装Microsoft .net FrameWork 4.0安装包;2. 安装ASP.NET MVC 3;3. 设置“Web扩展服务”中的“ASP.NET v4.0.0.30319”为允许,如下图所示:4. 在IIS中发布网站,创建虚拟目录,ASP.NET版本选择4.0.30196;5. 添加MVC的解析:右击IIS中的网站选择“属性”-“主目录”-“配置”-“映射”-“插入”,配置如下:可执行文件:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30196\aspnet_isapi.dll,确认文件是否存在:不选中点击确定,最后如下图所示:I
阅读全文
摘要:一、JSON MVC And JQuery In case you are new to JSON please read this before moving ahead with this lab ,What is JSON ?.So in this lab we will expose a simple “Customer” object from MVC in JSON format and consume the same using Jquery. For this lab please ensure that the project is created by using ba.
阅读全文
摘要:IntroductionThis article introduces Entity Framework to absolute beginners. The article is meant for developers who are primarily using ADO.NET to write their data access layers. Many experienced developers will find this article very basic but since the article is written from the perspective of be
阅读全文
摘要:二、Creating Custom Routes In this tutorial, you learn how to add a custom route to an ASP.NET MVC application. You learn how to modify the default route table in the Global.asax file with a custom route. For many simple ASP.NET MVC applications, the default route table will work just fine. However...
阅读全文
摘要:In this tutorial, Stephen Walther introduces you to ASP.NET MVC controllers. You learn how to create new controllers and return different types of action results. This tutorial explores the topic of ASP.NET MVC controllers, controller actions, and action results. After you complete this tutorial,...
阅读全文