zoukankan      html  css  js  c++  java
  • 在.net core项目中想使用类似iis上面虚拟目录的功能

    事实上iis是不支持.net core mvc项目虚拟目录的。你在iis上发布网站 然后在wwwroot目录上创建虚拟目录,指向硬盘其他位置上的文件夹,是不会有效果的。

    正确的处理方式应该是修改静态文件中间件

    这里直接晒出代码:

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
            public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                else
                {
                    app.UseExceptionHandler("/Error");
                }
                //注意 这是用来处理请求静态文件的中间件 还有专门针对请求目录的中间件UseDirectoryBrowser()
                //推荐文章 https://www.jb51.net/article/99303.htm
                //使用静态文件 默认指向wwwroot
                app.UseStaticFiles();
                //再插入一个中间件,这次不使用默认的
                app.UseStaticFiles(new StaticFileOptions()
                {
                    //FileProvider是专门用来读取静态文件的
                    FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"G:Video")),
                    //如果请求的路径是以下的这个路径 就用上面这个FileProvider
                    RequestPath = new PathString("/gVideos")
                });
                app.UseStaticFiles(new StaticFileOptions()
                {
                    FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"I:video")),
                    RequestPath = new PathString("/iVideos")
                });
                app.UseStaticFiles(new StaticFileOptions()
                {
                    FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"J:video")),
                    RequestPath = new PathString("/jVideos")
                });
                app.UseCookiePolicy();
    
                app.UseMvc();
            }

    参考的文章:https://www.jb51.net/article/99303.htm 这篇文章非常值得一看

  • 相关阅读:
    UVA.12096 The SetStack Computer ( 好题 栈 STL混合应用)
    HDOJ(HDU).1412 {A} + {B} (STL SET)
    UVA.10474 Where is the Marble ( 排序 二分查找 )
    HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)
    HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)
    17 西安
    17 沈阳
    13 南京
    10/11 作战会议
    2019牛客国庆集训派对day5
  • 原文地址:https://www.cnblogs.com/wholeworld/p/9888154.html
Copyright © 2011-2022 走看看