ASP.NET MVC 访问静态文件
When use asp.net MVC, we can add a special route to access the image files. the code like below:
1. in RouteConfig.cs file, add the code marked in yellow.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace Mediakind.Mds.YouTube.Server
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
//routes.RouteExistingFiles = false;
//routes.IgnoreRoute("Content/{*relpath}");
//routes.IgnoreRoute("Scripts/{*relpath}");
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
//The route for access the static image file
routes.MapRoute(
name: "images",
url: "images/{*filename}",
defaults: new { controller = "Images", action = "Index" }
);
}
}
}
2. add another controller named "ImagesController", the file is "ImagesController.cs", and the code as :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Mvc;
namespace Mediakind.Mds.FakeServer.ExternalSearch
{
[Route]
public class ImagesController : Controller
{
public void Index(string filename)
{
Response.WriteFile(@"images/" + filename);
}
}
}
(End)
ASP.NET MVC 访问静态文件的更多相关文章
- asp.net mvc 访问.html文件
把html页面放在除Views文件夹外的任意文件夹,如Htmls--123.html,url直接访问便可,如 http://yourname/htmls/123.html 可以在路由表中排出不需要路由 ...
- 基于 Vue.js 之 iView UI 框架非工程化实践记要 使用 Newtonsoft.Json 操作 JSON 字符串 基于.net core实现项目自动编译、并生成nuget包 webpack + vue 在dev和production模式下的小小区别 这样入门asp.net core 之 静态文件 这样入门asp.net core,如何
基于 Vue.js 之 iView UI 框架非工程化实践记要 像我们平日里做惯了 Java 或者 .NET 这种后端程序员,对于前端的认识还常常停留在 jQuery 时代,包括其插件在需要时就引 ...
- SPRING-MVC访问静态文件,如jpg,js,css
如何你的DispatcherServlet拦截 *.do这样的URL,就不存在访问不到静态资源的问题.如果你的DispatcherServlet拦截“/”,拦截了所有的请求,同时对*.js,*.jpg ...
- Asp.Net MVC页面静态化功能实现二:用递归算法来实现
上一篇提到采用IHttpModule来实现当用户访问网站的时候,通过重新定义Response.Filter来实现将返回给客户端的html代码保存,以便用户下一次访问是直接访问静态页面. Asp.Net ...
- Asp.Net MVC页面静态化功能实现一:利用IHttpModule,摒弃ResultFilter
上一篇有提到利用IHttpModule和ResultFilter实现页面静态化功能.后来经过一些改动,将ResultFilter中要实现的功能全部转移到IHttpModule中来实现 Asp.Net ...
- Asp.Net MVC页面静态化功能实现一:利用IHttpModule和ResultFilter
由于公司现在所采用的是一套CMS内容管理系统的框架,所以最近项目中有一个需求提到要求实现页面静态化的功能.在网上查询了一些资料和文献,最后采用的是小尾鱼的池塘提供的 利用ResultFilter实现a ...
- SpringBoot学习笔记(二):SpringBoot访问静态文件、捕获全局异常、集成Thymeleaf、集成JSP
SpringBoot访问静态文件 什么是静态文件? 不需要通过web容器去得到的文件,直接通过路径就能得到的文件,比如项目的css,js,img等文件. 所有的资源文件都应该在src/main/res ...
- [代码示例]用Fine Uploader+ASP.NET MVC实现ajax文件上传
原文 [代码示例]用Fine Uploader+ASP.NET MVC实现ajax文件上传 Fine Uploader(http://fineuploader.com/)是一个实现 ajax 上传文件 ...
- spingmvc 访问静态文件,比如css,img等
这里我来引用一段别人的原话 url-pattern有5种配置模式: (1)/xxx:完全匹配/xxx的路径 (2)/xxx/*:匹配以/xxx开头的路径,请求中必须包含xxx. (3)/*:匹配/下的 ...
随机推荐
- tensorflow(4)踩过的一些坑
版本问题 1.1 版本的一个BUG ValueError: Variable rnn/basic_lstm_cell/weights already exists, disallowed. 结合这个文 ...
- PyAutoGUI使用
PyAutoGUI是一个纯Python的GUI自动化工具,其目的是可以用程序自动控制鼠标和键盘操作,利用它可以实现自动化任务,再也不用担心有重复枯燥的任务了. 安装: pip install pyau ...
- 关于网站的一些js和css常见问题的记录
1. 文字超过宽度,给这个后面超过的文字用...来表示 white-space: nowrap;
- Java课程02-动手动脑
1.编写一个方法,生成一千个随机数,纯随机数发生器. package random; public class random { public static void main(String[] ar ...
- ubuntu18.04 安装pip3
Ubuntu18.04默认内嵌python2.python3,pip安装时,python2对应安装pip,python3对应安装pip3. sudo apt install python3-pip 检 ...
- ngx-admin with Asp.net Core 2.0, possibly plus OrchardCore
1 Download ngx-admin from https://github.com/akveo/ngx-admin 2 Create a new Web Application in vs201 ...
- Git 教程(二):提交和回退
我们已经成功地添加并提交了一个readme.txt文件,现在,是时候继续工作了,于是,我们继续修改readme.txt文件,改成如下内容: Git is a distributed version c ...
- 【DOM练习】淘宝购物车
HTML: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <tit ...
- BUAA Summer Practice 2017 #1 字符串专场
https://vjudge.net/contest/262753#overview C - Regular Number HDU - 5972 bitset temp, temp[i]=1表示 此前 ...
- IPv4的编址方法
重难点: 1.IP地址有3位标识符,由ICANN进行分配. 2.两级的IP地址分为 ::={<网络号>,<主机号>}. 3.在同一个局域网上的主机或路由器的IP地址中的网络号必 ...