
一般当Server关闭时:服务器关闭的时候
所以:服务器关闭的时候,Servlet被销毁
IIS建立发布,然后客户端同时可以上传下载就好了,中间用服务器做缓存。文件先上传到服务器,再在别的客户端上下载到本地,销毁服务器数据。如果你希望看到上传进度,那就让他显示服务器文件大小就好了。
protected void BtnUpload_Click(object sender, EventArgs e){
if (FileUpload1HasFile)
{
string upPath = "/up/"; //上传文件路径
int upLength = 5; //上传文件大小
string upFileType = "|image/bmp|image/x-png|image/pjpeg|image/gif|image/png|image/jpeg|";
string fileContentType = FileUpload1PostedFileContentType; //文件类型
if (upFileTypeIndexOf(fileContentTypeToLower()) > 0)
{
string name = FileUpload1PostedFileFileName; // 客户端文件路径
FileInfo file = new FileInfo(name);
string fileName = DateTimeNowToString("yyyyMMddhhmmssfff") + fileExtension; // 文件名称,当前时间(yyyyMMddhhmmssfff)
string webFilePath = ServerMapPath(upPath) + fileName; // 服务器端文件路径
string FilePath = upPath + fileName; //页面中使用的路径
if (!FileExists(webFilePath))
{
if ((FileUpload1FileBytesLength / (1024 1024)) > upLength)
{
ClientScriptRegisterStartupScript(thisGetType(), "upfileOK", "alert('大小超出 " + upLength + " M的限制,请处理后再上传!');", true);
return;
}
try
{
FileUpload1SaveAs(webFilePath); // 使用 SaveAs 方法保存文件
ClientScriptRegisterStartupScript(thisGetType(), "upfileOK", "alert('提示:文件上传成功');", true);
}
catch (Exception ex)
{
ClientScriptRegisterStartupScript(thisGetType(), "upfileOK", "alert('提示:文件上传失败" + exMessage + "');", true);
}
}
else
{
ClientScriptRegisterStartupScript(thisGetType(), "upfileOK", "alert('提示:文件已经存在,请重命名后上传');", true);
}
}
else
{
ClientScriptRegisterStartupScript(thisGetType(), "upfileOK", "alert('提示:文件类型不符" + fileContentType + "');", true);
}
}
}
//下载按钮
protected void BtnDownload_Click(object sender, EventArgs e)
{
string fileName = "aaajpg";//客户端保存的文件名
string filePath = ServerMapPath(@"~\up\20141103045852132jpg");//路径
//以字符流的形式下载文件
FileStream fs = new FileStream(filePath, FileModeOpen);
byte[] bytes = new byte[(int)fsLength];
fsRead(bytes, 0, bytesLength);
fsClose();
ResponseContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
ResponseAddHeader("Content-Disposition", "attachment; filename=" + > }
在HTML里就可以直接使用了:
<div><asp:FileUpload ID="FileUpload1" runat="server" Width="220px" />
<asp:Button ID="btn1" runat="server" CssClass="buttonClass" OnClick="BtnUpload_Click" Text="上传" />
<asp:Button ID="btn2" runat="server" onclick="BtnDownload_Click" Text="下载" />
</div>
前提条件两个客户端要能同时访问IIS服务器
以前曾经介绍过关于 KMS的用法 ,其中,提到了它的优点和用处,我们使用的场景有如下几点:如果脱离AWS,选择好像还真是不太多,Harshicorp的 Vault 是我仅知道的一个, RatticDB 算半个吧。
Vault提供了对token,密码,证书,API key等的安全存储(key/value)和控制,。它能处理key的续租、撤销、审计等功能。通过API访问可以获取到加密保存的密码、ssh key、X509的certs等。它的特性包括:
因为使用Vault的目的是为了
Vault存储[backend( >
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)