Beispiel #1
0
        // 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("/Home/Error");
                app.UseHsts();
            }

            #region 文件上传
            FileServerConfig config = app.ApplicationServices.GetService <FileServerConfig>();
            if (config != null && config.PathList != null)
            {
                List <PathItem> pathList = new List <PathItem>();
                foreach (PathItem pi in config.PathList)
                {
                    if (string.IsNullOrEmpty(pi.LocalPath))
                    {
                        continue;
                    }

                    try
                    {
                        if (!System.IO.Directory.Exists(pi.LocalPath))
                        {
                            System.IO.Directory.CreateDirectory(pi.LocalPath);
                        }
                        pathList.Add(pi);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("文件夹创建失败:\r\n{0}", e.ToString());
                    }
                }

                foreach (PathItem pi in pathList)
                {
                    app.UseStaticFiles(new StaticFileOptions()
                    {
                        FileProvider = new PhysicalFileProvider(pi.LocalPath),
                        RequestPath  = pi.Url
                    });
                    Console.WriteLine("路径映射:{0}-->{1}", pi.LocalPath, pi.Url);
                }
            }
            #endregion

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseSession();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Login}/{action=Loginin}/{id?}");
            });
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("config.json")
                                .Build();

            //log4net配置
            Repository = LogManager.CreateRepository("NETCoreRepository");
            XmlConfigurator.Configure(Repository, new System.IO.FileInfo("log4net.config"));

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            #region 文件上传
            var fs = configuration.GetSection("FileServer");
            FileServerConfig config = fs.Get <FileServerConfig>();
            services.AddSingleton(config);
            #endregion

            services.AddDbContext <UnifiedDbContext>(options =>
            {
                options.UseMySql(configuration["Data:DefaultConnection:ConnectionString"]);
            });
            services.AddSession();
            services.AddUserDefined();
        }
Beispiel #3
0
        internal static void InitConfig()
        {
            var config = new FileServerConfig
            {
                Site         = "http://file.dayeasy.dev/",
                DefaultImage = "/image/dayeasy.gif",
                MaxFileCount = 4000,
                Image        = new FileTypeLimit
                {
                    Exts    = new[] { ".jpg", ".jpeg", ".gif", ".png" },
                    MaxSize = 1024
                },
                Video = new FileTypeLimit
                {
                    Exts    = new[] { ".flv", ".mp4", ".swf", ".rm" },
                    MaxSize = 500 * 1024
                },
                Audio = new FileTypeLimit
                {
                    Exts    = new[] { ".ogg", ".mp3" },
                    MaxSize = 50 * 1024
                },
                Attach = new FileTypeLimit
                {
                    Exts    = new[] { ".rar", ".zip", ".7z", ".doc", ".docx" },
                    MaxSize = 100 * 1024
                },
                Mongo = new MongoConfig
                {
                    Servers = new List <MongoServer>
                    {
                        new MongoServer {
                            Host = "192.168.10.20", Port = 27015
                        }
                    },
                    Credentials = new List <MongoCredential>
                    {
                        new MongoCredential {
                            DataBase = "file_picture", User = "******", Pwd = "dayeasy@123"
                        },
                        new MongoCredential {
                            DataBase = "file_attach", User = "******", Pwd = "dayeasy@123"
                        }
                    }
                }
            };

            ConfigUtils <FileServerConfig> .Instance.Set(config);
        }
 public async Task <IActionResult> UpdateFileVisitUrl(string fileVisitUrl)
 {
     try
     {
         return(await Task.Run(() =>
         {
             FileServerConfig.SetFileVisitUrl(fileVisitUrl);
             LogHelper.Info($"文件访问路径修改为:{fileVisitUrl}");
             return Ok($"修改文件访问路径:{fileVisitUrl} 完成");
         }));
     }
     catch (Exception ex)
     {
         LogHelper.Error($"修改文件访问路径为:{fileVisitUrl} 发生了异常", ex);
         return(BadRequest(ex.Message));
     }
 }
 public async Task <IActionResult> GetConfig()
 {
     try
     {
         return(await Task.Run(() =>
         {
             var cfg = FileServerConfig.GetConfig();
             LogHelper.Info($"查询文件服务配置信息:ClientIP({HttpContext.GetClientIp()})");
             return Ok(cfg);
         }));
     }
     catch (Exception ex)
     {
         LogHelper.Error($"查询文件服务配置信息发生了异常:{ex.Message}");
         LogHelper.Error(ex);
         return(BadRequest(ex.Message));
     }
 }
Beispiel #6
0
 public FileController(FileServerConfig config)
 {
     _config = config;
 }