将文件上传到实际的服务器 [英] Upload file to the actual server

查看:76
本文介绍了将文件上传到实际的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在将网站发布到服务器后上传文件,

上传在本地完美运行但在发布此代码后无法上传到服务器



Trying to upload a file after publishing the site to the server,
uploading works perfectly in local but am not able to upload to the server after publish this my code

var uploadedFile = new UploadedFile();

                 for (int i = 0; i < Request.Files.Count; i++)
                 {
                     HttpPostedFileBase file = Request.Files[i];
                     int fileSize = file.ContentLength;
                     string fileName = file.FileName;
                     fileName = Path.GetFileName(file.FileName);
                     string mimeType = file.ContentType;
                     System.IO.Stream fileContent = file.InputStream;

                     file.SaveAs(Server.MapPath("~/Images/") + fileName);
                     }







当我上传到服务器时,即我之后应该更改上述代码发布???




should i change the above code when i am uploading to server i.e. after publishing ???

推荐答案

您应该允许从web.config访问Images文件夹。

例如我正在使用下一个设置:

< location path =Content / Images>

< system.web>

< identity impersonate = trueuserName =SomeUserpassword =UserPassword/>

< authorization>

< deny users =?/>

< / authorization>

< /system.web>

< / location>
You should allow from web.config the access to the Images folder.
For example I am using the next settings:
<location path="Content/Images">
<system.web>
<identity impersonate="true" userName="SomeUser" password="UserPassword"/>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>


这篇关于将文件上传到实际的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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