Пример #1
0
    protected override Task ExecuteAsync(HttpContext httpContext, string contentPath)
    {
        httpContext.RequestServices = GetServiceProvider();
        var actionContext = new ActionContext(httpContext, new(), new());

        var redirectResult = new RedirectResult(contentPath);

        return(redirectResult.ExecuteResultAsync(actionContext));
    }
Пример #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            Bootstrapper.Current.Configure(app, env);

            //if (env.IsDevelopment())
            //{
            //    app.UseDeveloperExceptionPage();
            //}
            app.Run(async(context) =>
            {
                //ActionContext ctx = new ActionContext();
                //ctx.HttpContext = context;

                //System.IO.FileStream stream = new System.IO.FileStream("/app/bin/Debug/netcoreapp2.0/test.py", System.IO.FileMode.Open);
                //byte[] buffer = new byte[stream.Length];
                //stream.Read(buffer, 0, buffer.Length);

                //FileResult rst = new FileResult(buffer, "text/plain")
                //{
                //    FileDownloadName = "test.py"
                //};

                //ActionContext ctx = new ActionContext();
                //ctx.HttpContext = context;

                //System.IO.FileStream stream = new System.IO.FileStream("/app/bin/Debug/netcoreapp2.0/test.py", System.IO.FileMode.Open);

                //FileResult rst = new FileResult(stream, "text/plain")
                //{
                //    FileDownloadName = "test.py"
                //};

                //ActionContext ctx = new ActionContext();
                //ctx.HttpContext = context;
                //FileResult rst = new FileResult("/app/bin/Debug/netcoreapp2.0/test.py");

                if (context.Request.Path.Value == "/redirect")
                {
                    ActionContext ctx  = new ActionContext();
                    ctx.HttpContext    = context;
                    RedirectResult rst = new RedirectResult("redirect2");
                    await rst.ExecuteResultAsync(ctx);
                }

                await context.Response.WriteAsync(context.Request.Path.Value);
            });
        }