资源简介

这个是一个小demo,用c# mvc返回图片类型的结果。用于希望不直接在img标签中指定文件路径或者在img标签不能使用绝对路径的情况下。还有一种情况就是如果你的图片资源存储在数据库里,那么用相似的方式都可以解决

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace 路径测试
{
    // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明,
    // 请访问 http://go.microsoft.com/?linkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute(“{resource}.axd/{*pathInfo}“);

            routes.MapRoute(
                “Default“ // 路由名称
                “{controller}/{action}/{id}“ // 带有参数的 URL
                new { controller = “Home“ action = “Index“ id = UrlParameter.Optional } // 参数默认值
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-11-06 21:54  路径测试\
     目录           0  2012-11-06 21:54  路径测试\packages\
     目录           0  2012-11-06 21:54  路径测试\packages\Entityframework.4.1.10331.0\
     文件      458371  2012-11-06 19:10  路径测试\packages\Entityframework.4.1.10331.0\Entityframework.4.1.10331.0.nupkg
     目录           0  2012-11-06 21:54  路径测试\packages\Entityframework.4.1.10331.0\lib\
     文件      783648  2012-11-06 19:10  路径测试\packages\Entityframework.4.1.10331.0\lib\Entityframework.dll
     文件      834489  2012-11-06 19:10  路径测试\packages\Entityframework.4.1.10331.0\lib\Entityframework.xml
     目录           0  2012-11-06 21:54  路径测试\packages\Modernizr.1.7\
     目录           0  2012-11-06 21:54  路径测试\packages\Modernizr.1.7\Content\
     目录           0  2012-11-06 21:54  路径测试\packages\Modernizr.1.7\Content\scripts\
     文件       37171  2012-11-06 19:10  路径测试\packages\Modernizr.1.7\Content\scripts\modernizr-1.7.js
     文件        9413  2012-11-06 19:10  路径测试\packages\Modernizr.1.7\Content\scripts\modernizr-1.7.min.js
     文件       20919  2012-11-06 19:10  路径测试\packages\Modernizr.1.7\Modernizr.1.7.nupkg
     目录           0  2012-11-06 21:54  路径测试\packages\jQuery.1.5.1\
     目录           0  2012-11-06 21:54  路径测试\packages\jQuery.1.5.1\Content\
     目录           0  2012-11-06 21:54  路径测试\packages\jQuery.1.5.1\Content\scripts\
     文件      217420  2012-11-06 19:10  路径测试\packages\jQuery.1.5.1\Content\scripts\jquery-1.5.1.js
     文件       85497  2012-11-06 19:10  路径测试\packages\jQuery.1.5.1\Content\scripts\jquery-1.5.1.min.js
     文件      107931  2012-11-06 19:10  路径测试\packages\jQuery.1.5.1\jQuery.1.5.1.nupkg
     目录           0  2012-11-06 21:54  路径测试\packages\jQuery.UI.Combined.1.8.11\
     目录           0  2012-11-06 21:54  路径测试\packages\jQuery.UI.Combined.1.8.11\Content\
     目录           0  2012-11-06 21:54  路径测试\packages\jQuery.UI.Combined.1.8.11\Content\Content\
     目录           0  2012-11-06 21:54  路径测试\packages\jQuery.UI.Combined.1.8.11\Content\Content\themes\
     目录           0  2012-11-06 21:54  路径测试\packages\jQuery.UI.Combined.1.8.11\Content\Content\themes\base\
     目录           0  2012-11-06 21:54  路径测试\packages\jQuery.UI.Combined.1.8.11\Content\Content\themes\base\images\
     文件         180  2012-11-06 19:10  路径测试\packages\jQuery.UI.Combined.1.8.11\Content\Content\themes\base\images\ui-bg_flat_0_aaaaaa_40x100.png
     文件         178  2012-11-06 19:10  路径测试\packages\jQuery.UI.Combined.1.8.11\Content\Content\themes\base\images\ui-bg_flat_75_ffffff_40x100.png
     文件         120  2012-11-06 19:10  路径测试\packages\jQuery.UI.Combined.1.8.11\Content\Content\themes\base\images\ui-bg_glass_55_fbf9ee_1x400.png
     文件         105  2012-11-06 19:10  路径测试\packages\jQuery.UI.Combined.1.8.11\Content\Content\themes\base\images\ui-bg_glass_65_ffffff_1x400.png
     文件         111  2012-11-06 19:10  路径测试\packages\jQuery.UI.Combined.1.8.11\Content\Content\themes\base\images\ui-bg_glass_75_dadada_1x400.png
     文件         110  2012-11-06 19:10  路径测试\packages\jQuery.UI.Combined.1.8.11\Content\Content\themes\base\images\ui-bg_glass_75_e6e6e6_1x400.png
............此处省略128个文件信息

评论

共有 条评论