コード例 #1
0
ファイル: Startup.cs プロジェクト: el7or/Zawaj
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, TrialData trialData)
        {
            string corsOrigin = "http://localhost:4200";

            //StripeConfiguration.SetApiKey(Configuration.GetSection("Stripe:SecretKey").Value);
            StripeConfiguration.ApiKey = Configuration.GetSection("Stripe:SecretKey").Value;
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(BuilderExtensions =>
                {
                    BuilderExtensions.Run(async context =>
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                        var error = context.Features.Get <IExceptionHandlerFeature>();
                        if (error != null)
                        {
                            context.Response.AddApplicationError(error.Error.Message, corsOrigin);
                            await context.Response.WriteAsync(error.Error.Message);
                        }
                    });
                });
                // app.UseHsts();
            }

            /* app.UseSpa(spa =>
             * {
             *  // To learn more about options for serving an Angular SPA from ASP.NET Core,
             *  // see https://go.microsoft.com/fwlink/?linkid=864501
             *
             *  spa.Options.SourcePath = "ZawajSPA";
             *
             *  if (env.IsDevelopment())
             *  {
             *      //spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");
             *      spa.UseAngularCliServer(npmScript: "start");
             *  }
             * });  */

            trialData.TrialUsers();
            app.UseHttpsRedirection();
            app.UseCors(x => x.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
            app.UseSignalR(options =>
            {
                options.MapHub <ChatHub>("/chatHub");
            });
            app.UseAuthentication();
            app.UseMvc();
        }
コード例 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, TrialData trialData)
        {
            StripeConfiguration.SetApiKey(Configuration.GetSection("Stripe:SecretKey").Value);
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                //  app.UseHsts();

                // for any error handler
                app.UseExceptionHandler(BuilderExtensions =>
                {
                    BuilderExtensions.Run(async context =>
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                        var error = context.Features.Get <IExceptionHandlerFeature>();
                        if (error != null)
                        {
                            context.Response.AddApplicationError(error.Error.Message);
                            await context.Response.WriteAsync(error.Error.Message);
                        }
                    });
                });
            }

            // app.UseMvc();
            // app.UseHttpsRedirection();

            trialData.TrialUsers();
            //app.UseCors(x =>x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials());
            app.UseCors();

            app.UseAuthentication();

            app.UseRouting();

            app.UseAuthorization();

            // in asp core 2.1  only
            //app.UseSignalR(routes => {  routes.MapHub<ChatHub>("/chat"); });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                // in asp core 3 above
                endpoints.MapHub <ChatHub>("/chat");
            });
        }
コード例 #3
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, TrialData trialData)
        {
            StripeConfiguration.SetApiKey(Configuration.GetSection("Stripe:SecretKey").Value);
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(BuilderExtensions => {
                    BuilderExtensions.Run(async context =>
                    {
                        context.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                        var error = context.Features.Get <IExceptionHandlerFeature>();
                        if (error != null)
                        {
                            context.Response.AddApplicationError(error.Error.Message);
                            await context.Response.WriteAsync(error.Error.Message);
                        }
                    });
                });
                //app.UseHsts();
            }

            trialData.TrialUsers();
            app.UseHttpsRedirection();

            app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials());
            app.UseSignalR(routes => {
                routes.MapHub <ChatHub>("/chat");
            });
            app.UseAuthentication();
            app.Use(async(context, next) =>
            {
                await next();
                if (context.Response.StatusCode == 404)
                {
                    context.Request.Path = "/index.html";
                    await next();
                }
            });
            app.UseDefaultFiles();
            app.UseStaticFiles();
            app.UseMvc();
        }