Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Web-在Asp.NETCore3.1中通过查询字符串调整图像大小_C#_Asp.net Core_Asp.net Core Middleware_Imagesharp - Fatal编程技术网

C# Web-在Asp.NETCore3.1中通过查询字符串调整图像大小

C# Web-在Asp.NETCore3.1中通过查询字符串调整图像大小,c#,asp.net-core,asp.net-core-middleware,imagesharp,C#,Asp.net Core,Asp.net Core Middleware,Imagesharp,我正在尝试使用ImageSharp.Web通过查询字符串参数调整图像大小,例如: 我创建了一个新的MVC Asp.Net Core 3.1项目,安装了软件包并遵循 我尝试了所描述的最小配置和几种变体,但似乎中间件没有拦截映像请求。我总是得到原始图像,不会触发任何错误 我错过什么了吗? 此功能的最低可能配置是什么 Tks Startup.cs: public void ConfigureServices(IServiceCollection services) {

我正在尝试使用ImageSharp.Web通过查询字符串参数调整图像大小,例如:

我创建了一个新的MVC Asp.Net Core 3.1项目,安装了软件包并遵循

我尝试了所描述的最小配置和几种变体,但似乎中间件没有拦截映像请求。我总是得到原始图像,不会触发任何错误

我错过什么了吗? 此功能的最低可能配置是什么

Tks

Startup.cs:

        public void ConfigureServices(IServiceCollection services)
    {

        services.AddDependencyInjectionSetup();
        services.AddControllersWithViews();

        //https://docs.sixlabors.com/articles/imagesharp.web/gettingstarted.html
        services.AddImageSharp();

        services.AddImageSharpCore(
            options =>
            {
                options.MaxBrowserCacheDays = 7;
                options.MaxCacheDays = 365;
                options.CachedNameLength = 8;
                options.OnParseCommands = _ => { };
                options.OnBeforeSave = _ => { };
                options.OnProcessed = _ => { };
                options.OnPrepareResponse = _ => { };
            })
            .SetRequestParser<QueryCollectionRequestParser>()
            .SetMemoryAllocator(provider => ArrayPoolMemoryAllocator.CreateWithMinimalPooling())
            .Configure<PhysicalFileSystemCacheOptions>(options =>
            {
                options.CacheFolder = "imagesharp-cache";
            })
            .SetCache<PhysicalFileSystemCache>()
            .SetCacheHash<CacheHash>()
            .AddProvider<PhysicalFileSystemProvider>()
            .AddProcessor<ResizeWebProcessor>()
            .AddProcessor<FormatWebProcessor>();


    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }

        app.UseStaticFiles();

        app.UseRouting();

        app.UseAuthentication();
        app.UseAuthorization();         

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });

        app.UseImageSharp();


    }
public void配置服务(IServiceCollection服务)
{
AddDependencyInjectionSetup();
services.AddControllersWithViews();
//https://docs.sixlabors.com/articles/imagesharp.web/gettingstarted.html
服务。AddImageSharp();
服务.AddImageSharpCore(
选项=>
{
options.MaxBrowserCacheDays=7;
options.MaxCacheDays=365;
options.CachedNameLength=8;
options.OnParseCommands=.=>{};
options.OnBeforeSave=\u=>{};
options.OnProcessed=\u=>{};
options.OnPrepareResponse=\u=>{};
})
.SetRequestParser()
.SetMemoryAllocator(提供程序=>ArrayPoolMemoryAllocator.CreateWithMinimalPooling())
.Configure(选项=>
{
options.CacheFolder=“imagesharp缓存”;
})
.SetCache()
.SetCacheHash()文件
.AddProvider()
.AddProcessor()
.AddProcessor();
}
public void配置(IApplicationBuilder应用程序、IWebHostEnvironment环境)
{
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
其他的
{
app.UseExceptionHandler(“/Home/Error”);
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(端点=>
{
endpoints.MapControllers();
});
app.useMageSharp();
}
调用

app.useMageSharp();
一定是在

app.UseStaticFiles();
正在发生的事情是,内置静态文件中间件甚至还没来得及使用ImageSharp。。在startup.cs的
Configure()
部分中注册项目的顺序很重要,因为这是它们运行的顺序。

调用

app.useMageSharp();
一定是在

app.UseStaticFiles();

正在发生的事情是,内置静态文件中间件甚至还没来得及使用ImageSharp。。您在startup.cs的
Configure()
部分中注册项目的顺序很重要,因为这是它们运行的顺序。

有效!我的想法正好相反,UseMageSharp()依赖于UseStaticFiles()并将覆盖它。我还必须删除services.AddImageSharpCore()并将配置直接应用于services.AddImageSharp()才能工作。太多了!它起作用了!我的想法正好相反,UseMageSharp()依赖于UseStaticFiles()并将覆盖它。我还必须删除services.AddImageSharpCore()并将配置直接应用于services.AddImageSharp()才能工作。太多了!