代码之家  ›  专栏  ›  技术社区  ›  Tom Crosman

为什么Microsoft.aspnetcore.odata要打破我的狂妄?

  •  0
  • Tom Crosman  · 技术社区  · 7 年前

    我已经在.NETCore3.0WebAPI项目中大摇大摆地运行了很长一段时间,没有任何问题。

    我刚从Nuget商店安装了Microsoft.aspnet.odata。我想我一定是在配置文件中出错了。

    odata正在工作,但我的swashback中间件不工作。

    代码如下: 注意:我知道还有其他的中间件是草率的,但是在添加关于odata的行之前,它已经全部工作了。

    我试着搞乱语法的顺序,但运气不好。我知道是什么破坏了它,但描述起来有困难。

    namespace MyProjectPortalVueJs
    {
        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.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
                services.AddAuthentication(sharedOptions =>
                {
                    sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                    sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
                })
                .AddAzureAd(options =>
                {
                Configuration.Bind("AzureAd", options);
                AzureAdOptions.Settings = options;
                })
                .AddCookie();
                // Add framework services.
                services.AddMvc()
                //UNSURE WHAT THE COMPATIBILITY WAS DOING.  CHANGED ON 4-16-2019
                //.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
                .AddSessionStateTempDataProvider();
                services.AddSession();
                // Simple example with dependency injection for a data provider.
                services.AddSingleton<Providers.IWeatherProvider, Providers.WeatherProviderFake>();
    
    
    
    
                // Register the Swagger generator, defining 1 or more Swagger documents
                services.AddSwaggerGen(c =>
                {
                    c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
                });
    
                services.AddOData();
            }
    
            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
            public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                // Enable middleware to serve generated Swagger as a JSON endpoint.
                app.UseSwagger();
    
                // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), 
                // specifying the Swagger JSON endpoint.
                app.UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
                });
    
    
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
    
                    // Webpack initialization with hot-reload.
                    app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
                    {
                        HotModuleReplacement = true,
                    });
                }
                else
                {
                    app.UseExceptionHandler("/Home/Error");
                }
    
                app.UseStaticFiles();
                app.UseSession(); // Needs to be before app.UseAuthentication() and app.UseMvc() otherwise you will get an exception "Session has not been configured for this application or request."
                app.UseAuthentication();
                app.UseMvc(routes =>
                {
                    routes.EnableDependencyInjection();
                    routes.Expand().Select().Count().OrderBy().Filter();
    
                    routes.MapRoute(
                        name: "default",
                        template: "{controller=Home}/{action=Index}/{id?}");
    
                    routes.MapSpaFallbackRoute(
                        name: "spa-fallback",
                        defaults: new { controller = "Home", action = "Index" });
                });
            }
        }
    }
    
    0 回复  |  直到 7 年前