// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseCors("AllowAll"); //app.UseSession(); // if (!env.IsDevelopment() || ResponseBuilder.isUserException) // { //app.UseDeveloperExceptionPage(); ExceptionHandlerOptions options = new ExceptionHandlerOptions(); //options. app.UseExceptionHandler(options => { options.Run(async context => { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; context.Response.ContentType = "application/json"; var ex = context.Features.Get <IExceptionHandlerFeature>(); if (ex != null) { if (!ResponseBuilder.isUserException) { CurrentInstance.IP = context.Connection.RemoteIpAddress.ToString(); new PKG_ERROR_LOGS().LogException(CurrentInstance.userID, ex.Error.Message.ToString(), ex.Error.StackTrace.ToString(), context.Request.Path.ToString(), CurrentInstance.IP, context.Request.QueryString.ToString()); } var err = ""; err = ResponseBuilder.Error(ex.Error.Message, Configuration["error_text"].ToString(), env.IsDevelopment()); ResponseBuilder.isUserException = false; //err = new ResponseBuilder().Error(Configuration["error_text"].ToString()); await context.Response.WriteAsync(err).ConfigureAwait(false); } }); }); // } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseSession(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseCors("AllowAll"); //app.UseSession(); // if (!env.IsDevelopment() || ResponseBuilder.isUserException) // { //app.UseDeveloperExceptionPage(); ExceptionHandlerOptions options = new ExceptionHandlerOptions(); //options. app.UseExceptionHandler(options => { options.Run(async context => { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; context.Response.ContentType = "application/json"; var ex = context.Features.Get <IExceptionHandlerFeature>(); if (ex != null) { if (!ResponseBuilder.isUserException) { CurrentInstance.IP = context.Connection.RemoteIpAddress.ToString(); new PKG_ERROR_LOGS().LogException(CurrentInstance.userID, ex.Error.Message.ToString(), ex.Error.StackTrace.ToString(), context.Request.Path.ToString(), CurrentInstance.IP, context.Request.QueryString.ToString()); } var err = ""; err = ResponseBuilder.Error(ex.Error.Message, Configuration["error_text"].ToString(), env.IsDevelopment()); ResponseBuilder.isUserException = false; //err = new ResponseBuilder().Error(Configuration["error_text"].ToString()); await context.Response.WriteAsync(err).ConfigureAwait(false); } }); }); // } app.UseHttpsRedirection(); app.UseRouting(); var webSocketOptions = new WebSocketOptions() { KeepAliveInterval = TimeSpan.FromSeconds(120), ReceiveBufferSize = 4 * 1024 }; //webSocketOptions.AllowedOrigins.Add("https://client.com"); app.UseWebSockets(webSocketOptions); app.UseAuthorization(); app.UseSession(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.Use(async(context, next) => { if (context.Request.Path == "/Chat") { if (context.WebSockets.IsWebSocketRequest) { await new ChatService().GetAndSendMessage(context); } else { context.Response.StatusCode = 400; } } else { await next(); } }); }