小编Har*_*hah的帖子

如何通过"保存对话框"从ASP.NET MVC中的Azure下载PDF文件

我有一个存储在Azure存储上的文件,我需要从ASP.NET MVC控制器下载.下面的代码实际上工作正常.

string fullPath =  ConfigurationManager.AppSettings["pdfStorage"].ToString() + fileName ;
Response.Redirect(fullPath);
Run Code Online (Sandbox Code Playgroud)

但是,PDF将在同一页面中打开.我希望通过"保存"对话框下载文件,以便用户保持在同一页面上.在转移到Azure之前,我可以写

return File(fullPath, "application/pdf", file);
Run Code Online (Sandbox Code Playgroud)

但是Azure无法正常工作.

c# asp.net asp.net-mvc azure azure-storage

6
推荐指数
2
解决办法
3001
查看次数

使用 CLI 在 Azure Redis 中使用多个数据库

我们正在使用 Azure redis,并希望将数据分区到多个数据库中。请注意,我们使用的是单个 Redis 服务器而不是集群,因此我不是在谈论服务器上的分区。我读到 Azure Redis 默认有 16 个数据库。使用 StackExchange.Redis,我可以通过编程方式设置数据库 1 和数据库 0 中的键。

但是,当我使用常见的 redis CLI 命令(例如 CONFIG GET Databases)时,它显示未知命令。如果我使用 SELECT xx (选择数据库 xx)然后发出 Keys *,它仍然显示数据库 0 的键。

azure redis

5
推荐指数
0
解决办法
466
查看次数

使用 Ninject 在类中注入字符串属性

我的一个接口有一个字符串属性,该属性取决于接口的使用位置。我想避免每次创建对象时对属性进行硬编码。我可以在构造函数中设置属性,但对象是使用工厂注入的。界面如下:

public interface IObjectStore
{
    string StorageTableName { get; set;}

    void UpdateObjectStore(string key, string value);

    string ReadObjectStore(string key);
}
Run Code Online (Sandbox Code Playgroud)

哪个在服务中使用

public class CategoryService<T> : ICategoryService<T> where T : Company
{
    private readonly IObjectStore objectStore;

    public CategoryService(IObjectStore objStore)
    {
        this.objectStore = objStore;
        objectStore.StorageTableName = "CategoryTable"; // I want to avoid this hard coding
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

服务是使用服务工厂(Ninject.Extensions.Factory)创建的

 public interface IServiceFactory
{
    ICategoryService<T> CreateCategoryService<T>() where T : class;
}
Run Code Online (Sandbox Code Playgroud)

然后在控制器级别使用 Ninject 注入。这是我的绑定

bool storeInNoSql = true;
kernel.Bind<IServiceFactory>().ToFactory().InSingletonScope();
kernel.Bind<ICategoryService<Article>>().To<CategoryService<Article>>();
kernel.Bind<IObjectStore>().ToMethod(ctx => storeInNoSql ? …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc dependency-injection

3
推荐指数
1
解决办法
1286
查看次数