public void Configure(IApplicationBuilder app)
{
// ...
var staticFileOptions = new StaticFileOptions
{
OnPrepareResponse = (context) =>
{
var fn = context.File.Name.ToLowerInvariant();
if (fn == "random.jpg")
{
var width = context.Request.Query["w"];
var height = context.Request.Query["h"];
// Your logic here
}
else
{
// Some default logic for all other files
context.Context.Response.Headers.Add("Cache-Control", "public, max-age=15552000"); // 180 days
}
}
};
app.UseStaticFiles(staticFileOptions);
// ...
}
I am doing my best in .NET freelancing. Keen on diving into Blockchain #BUIDL. About.Me/Dmitry.Pavlov
Member
3 Points
40 Posts
Is there a filter for static file request?
Apr 14, 2017 03:24 AM|markblank05|LINK
is there a way to intercept or filter the request before serving the file? like if i request
so i can get the random.jpg the w and the h, then return it as an image
i tried intercepting it using MapRoute and it doesn't work when i use app.UseStaticFiles();
All-Star
15186 Points
3888 Posts
Re: Is there a filter for static file request?
Apr 14, 2017 07:01 AM|raju dasa|LINK
Hi,
use action method for processing image.
url like: localhost:5000/controllName/ActionName?image=random.jpg&w=100&h=100
rajudasa.blogspot.com || rajudasa-tech
Member
3 Points
40 Posts
Re: Is there a filter for static file request?
Apr 14, 2017 07:09 AM|markblank05|LINK
i also tried it, but I want it to look more natural when using in img tag, so it will be
is there a way to intercept the staticfile request?
Member
97 Points
37 Posts
MVP
Re: Is there a filter for static file request?
Apr 14, 2017 12:04 PM|dimaka|LINK
You can try this: