如何以编程方式设置 ImageResizer SQLReader 插件 v4 的配置?

How do I programmatically set configuration for the ImageResizer SQLReader plugin v4?

我之前使用的是 ImageResizer v3,但现在我正在尝试使用 v4。

参见:http://imageresizing.net/docs/v4/plugins/sqlreader

我需要以编程方式为 SQLReader 插件设置几个配置选项。我有这个以前的代码,但它不再有效,指出无法找到 SqlReaderSettings 类型:

        // SqlReader Plugin
        var fileSettings = new SqlReaderSettings
        {
            ConnectionString = ApplicationConfigurationContext.Current.DefaultSiteSqlConnectionString,
            PathPrefix = "~/Images",
            StripFileExtension = true,
            ImageIdType = SqlDbType.UniqueIdentifier,
            ImageBlobQuery = ???,
            ModifiedDateQuery = ???,
            ImageExistsQuery = ???,
            CacheUnmodifiedFiles = true,
            RequireImageExtension = true
        };

我无法使用 web.config 文件来存储其中的一些设置。具体来说,连接字符串可能会在 运行 时发生变化,并且由于公司政策,无法以未加密的方式存储在 web.config 文件中。

感谢您的帮助。


更新:这是我现在使用的代码。我没有从 Web.config 添加这个插件,因为它是多余的。

        new SqlReaderPlugin
        {
            ConnectionString = ApplicationConfigurationContext.Current.DefaultSiteSqlConnectionString,
            ImageIdType = SqlDbType.VarChar,
            QueriesAreStoredProcedures = true,
            ModifiedDateQuery = "procFileImageResizerSelectTimestamps",
            ImageBlobQuery = "procFileImageResizerSelectData",
            ExposeAsVpp = true,
            VirtualFilesystemPrefix = filesUri,
            RequireImageExtension = true,
            StripFileExtension = true,
            CacheUnmodifiedFiles = true

        }.Install(Config.Current);

可以直接将SqlReaderSettings替换为SqlReaderPlugin;它没有 longer uses a separate settings class。几乎所有 class 成员都应该相同,所以只需更改您正在初始化的 class 的名称即可。