コード例 #1
0
ファイル: SiteData.cs プロジェクト: mikaelm12/ProxyDemo
 public SiteData(Request[] requests)
 {
     this.request = requests;
     GetRequests = requests.Where(r => r.MethodType == "GET").Count();
     PostRequests = requests.Where(r => r.MethodType == "POST").Count();
     DeleteRequest = requests.Where(r => r.MethodType == "DELETE").Count();
     PutRequests = requests.Where(r => r.MethodType == "PUT").Count();
 }
コード例 #2
0
ファイル: Startup.cs プロジェクト: mikaelm12/ProxyDemo
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.MinimumLevel = LogLevel.Information;
            loggerFactory.AddConsole();

            // Configure the HTTP request pipeline.

            // Add the following to the request pipeline only in development environment.
            if (env.IsDevelopment())
            {
                app.UseErrorPage();
                app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // sends the request to the following path or controller action.
                app.UseErrorHandler("/Home/Error");
            }

            // Add static files to the request pipeline.
            app.UseStaticFiles();

            // Add cookie-based authentication to the request pipeline.
            app.UseIdentity();

            // Add authentication middleware to the request pipeline. You can configure options such as Id and Secret in the ConfigureServices method.
            // For more information see http://go.microsoft.com/fwlink/?LinkID=532715
            // app.UseFacebookAuthentication();
            // app.UseGoogleAuthentication();
            // app.UseMicrosoftAccountAuthentication();
            // app.UseTwitterAuthentication();

            app.Use(next =>
            {
                return async context =>
                {
                    var DbContext = (ApplicationDbContext)context.RequestServices.GetService(typeof(ApplicationDbContext));
                    var request = new Request();
                    if (!context.Request.Path.ToString().Contains("secret-route"))
                    {
                        var url = $"{context.Request.Scheme}://{host}:{ context.Connection.RemotePort} { context.Request.PathBase}{ context.Request.Path}{ context.Request.QueryString}";
                        request.MethodType = context.Request.Method.ToString();
                        request.Url = url;
                        request.TimeStamp = DateTime.Now;
                        DbContext.Add(request);
                        DbContext.SaveChanges();
                    }

                    await next(context);
                };
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "secret-route/{controller=Home}/{action=Index}/{id?}");
                });

            var options = new ProxyOptions()
            {
                Scheme = "https",
                Host = host,
                Port = "443"
            };

            app.RunProxy(options);
        }