• 在.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 这篇文章非常值得一看

  • 相关阅读:
    ubuntu下Nodic开发环境搭建
    usb_modeswitch移植
    STM32F4编程手册学习2_内存模型
    STM32F4 编程手册学习1_编程模型
    ARM架构中的程序执行与调用
    锲形文字 数字
    疑问
    lisp 题目
    面试官在面试时让我去破解一个软件,我成功了
    php CI ip限制
  • 原文地址:https://www.cnblogs.com/wholeworld/p/9888154.html
Copyright © 2020-2023  润新知