MVC 从控制器将数据对象赋值给前端JS对象

@{ Layout = null;} 示例 //将数据对象转换为 JSON 格式,是为了在网页中通过使用JS将数据作为文本进行处理 var data = @Html.Raw(Json.Encode(ViewBag.Data)); for (var i = 0; i < data.length; …… 阅读全文

MVC自定义路由实现URL重写,SEO优化

//App_Start-RouteConfig.cs public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); …… 阅读全文

WebApi接口返回json,xml,text纯文本等

[Route("api/Message/MessageList/")][HttpGet]public HttpResponseMessage MessageList(){ ResponseResult obj = new ResponseResult(); var pageData = Ydt.ExtLib.DataTableHelper.DataTableToList(re …… 阅读全文

C#对图片进行马赛克处理,可控制模糊程度

using System.Drawing;using System.Drawing.Imaging;using System.Web.Mvc;namespace MVC2017_Sample.Controllers{ public class DefaultController : Controller { public ActionResult Inde …… 阅读全文

ASP.NET/C# 获取当前目录、当前完整路径、文件全路径、目录、扩展名、文件名称

using System;using System.IO;namespace ConsoleApp5{ class Program { /* C# 获取当前目录、当前路径、文件全路径、目录、扩展名、文件名称 */ static void Main(string[] args) { ... …… 阅读全文

MVC中全局错误拦截记录日志,WebApi中全局错误拦截以及授权验证401,jquery cors 跨域

using Magic.Tool;using System;using System.Web;using System.Web.Mvc;using System.Web.Routing;//MVC中全局错误拦截namespace Magic.Mvc{ public class MvcApplication : System.Web.HttpApplication ... …… 阅读全文

ASP.NET缓存Cache的应用-提高数据库读取速度

一、 Cache概述 既然缓存中的数据其实是来自数据库的,那么缓存中的数据如何和数据库进行同步呢?一般来说,缓存中应该存放改动不大或者对数据的实时性没有太多要求的数据。这样,我们只需要定期更新缓存就可以了。相反,如果缓存的更新频率过快的话,使用缓存的意义就不是很大了,因此更新缓存的时候需要一次性从数据库中读取大量的数据,过于频繁地更新缓存反而加重了数据库的负担。那么ASP.NET中的C …… 阅读全文

使用微软URLRewriter实现URL重写

1、下载安装MSDNURLRewriting.msi。 开源代码http://download.microsoft.com/download/0/4/6/0463611e-a3f9-490d-a08c-877a83b797cf/MSDNURLRewriting.msi,下载下来后编译一下就可以了。编译后得到URLRewriter.dll和ActionlessForm.dll两 …… 阅读全文