Startup.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using WebApplication1.Models;


namespace WebApplication1
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            services.AddDbContext<DataDbcontext>(optionsBuilder =>
            {
                var dataAppSetting = Configuration.GetSection("ConnectionSetting");
                if (dataAppSetting == null)
                {
                    throw new Exception("没有配置数据库连接");
                }
                optionsBuilder.UseSqlServer(dataAppSetting["UserConnectionString"], option => option.EnableRetryOnFailure());
            });
            //取cofig值
            services.Configure<Dingconfig>(Configuration.GetSection("AppSettings"));
            //获取服务器路径
            services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            Common.WebCore.Utils.HttpContext.serviceCollection = services;
            services.Configure<FormOptions>(options =>
            {//设置上传文件大小
                options.MultipartBodyLengthLimit = 60000000;
            });
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,DataDbcontext  dataDbcontext)
        {

            //跨域
            app.UseHttpsRedirection().UseCors(builder =>
            builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
            if (env.IsDevelopment())
后面还有 28 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读 AI

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。