在中等信任存储ASP.NET临时用户文件 [英] Storing temporary user files in ASP.NET in medium trust

查看:162
本文介绍了在中等信任存储ASP.NET临时用户文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我的ASP.NET Web应用程序的用户提交的包括文本信息和图像推荐。提交过程有以下几个步骤:

I have a scenario where users of my ASP.NET web application submit testimonials consisting of text info and images. The submit process has the following steps:


  • 首先,用户输入的内容,并选择一个路径到图像

  • 当他点击preVIEW,该信息再次显示,这样他就可以确认

  • 一旦确认相关信息被持久化到数据库

这样做的问题是,我不希望上传的图片存储在数据库中的用户实际确认之前。相反,我把它们存储的临时文件,并把它们在DB后,才最终确认。

The problem with this is that I don't want to store uploaded images in the DB before the user actually confirms. Instead I store them as temporary files and put them in DB only after final confirmation.

由于我也希望我的应用程序在中等信任跑,我有写的权限只对应用程序目录和无处外面。我甚至想限制写权限为ASPNET / Network Service用户的〜/ App_Data文件夹。我的方案的问题是,一旦一个临时文件此文件夹中创建的应用程序池被回收,我不希望在每个证明提交。

Since I also want my application to run in medium trust, I have write permissions only to the application directory and nowhere outside. I even want to limit write permissions for the ASPNET / NETWORK SERVICE user to the ~/App_Data folder. The problem with my scenario is that once a temporary file is created in this folder, the application pool is recycled and I don't want that on every testimonial submit.

你怎么劝我把这些临时文件呢?只有在创建或重命名 - 如果我更新文件池不重新启动。但我不认为我可以存储整个图像中所有用户的单个文件。你觉得呢?

How do you advise I keep these temp files instead? The pool is not restarted if I update a file - only on create or rename. But I don't think I can store whole images in a single file for all users. What do you think?

更新:我要指出,我使用上传第三方控制。它给我的上传后的文件内容的二进制流进行编程访问,但我不能让这第二次回发后(第一步和回传实际执行上载)。

UPDATE: I should note that I'm using a third party control for upload. It gives me programmatic access to the binary stream of the file contents after upload, but I cannot keep this after a second postback (the first step and postback actually does the upload).

推荐答案

我会推荐的 IsolatedStorage 。这是一种虚拟文件夹中。

I would recommend IsolatedStorage. It's a kind of virtual folder.

下面是上$ C $的CProject 一个例子:

IsolatedStorageFileStream stream = 
  new IsolatedStorageFileStream(ISOLATED_FILE_NAME, 
  FileMode.Create, isoStore);

StreamWriter writer = new StreamWriter( stream );
writer.WriteLine( "This is my first line in the isolated storage file." );
writer.WriteLine( "This is second line." );
writer.Close();

更新:要清理您的文件,只是这样做:

UPDATE: To clean up your file just do this:

string fileName = "isolatestorage.txt";

IsolatedStorageFile storage = IsolatedStorageFile.GetStore(
    IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);

string[] files = storage.GetFileNames(fileName);
foreach(string file in files) {
    if(file == fileName) {
        storage.DeleteFile(file);
        break;
    }
}

这篇关于在中等信任存储ASP.NET临时用户文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆