qq_22993901
老来哥
2018-08-21 06:28

fileupload本地图片上传成功,上传到主机后出错

20
  • 服务器

上传代码:
if(FileUpload1.HasFile)
{
string FullName = FileUpload1.PostedFile.FileName;//获取图片物理地址
FileInfo fi = new FileInfo(FullName);
string name = fi.Name;//获取图片名称
string type = fi.Extension;//获取图片类型
string ImageTitle = TextBox1.Text;
if (type == ".jpg" || type == ".gif" || type == ".bmp" || type == ".png")
{
string filename = FileUpload1.FileName;
string fileext = System.IO.Path.GetExtension(filename);
string filenamaes = "xiangce" + DateTime.Now.ToString("yyyyMMddHHffss") + fileext;
fengmian_name = filenamaes;

            string SavePath = Server.MapPath("~\\ftp6247338\\Web\\picpage\\images");//图片保存到文件夹下
            this.FileUpload1.PostedFile.SaveAs(SavePath + "\\" + fengmian_name);//保存路径
            this.Image9.Visible = true;
            this.Image9.ImageUrl = "~\\ftp6247338\\Web\\picpage\\images" + "\\" + fengmian_name;//界面显示图片
            //string pic_addtime = DateTime.Now.ToString("yyyy/MM/dd");

            fengmian_addr = "../ftp6247338/Web/picpage/images/" + fengmian_name;
            admin_fengmian_addr = "~\\ftp6247338\\Web\\picpage\\images" + "\\" + fengmian_name;
            //fengmian_name = name ;
        }
        else
        {
            this.label6.Text = "请选择正确的格式图片";
        }

错误类型:

“/”应用程序中的服务器错误。

安全性异常
说明: 应用程序尝试执行安全策略不允许的操作。要授予此应用程序所需的权限,请与系统管理员联系,或在配置文件中更改该应用程序的信任级别。

异常详细信息: System.Security.SecurityException: 请求“System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”类型的权限已失败。

源错误:

行 267: {
行 268: string FullName = FileUpload1.PostedFile.FileName;//获取图片物理地址
行 269: FileInfo fi = new FileInfo(FullName);
行 270: string name = fi.Name;//获取图片名称
行 271: string type = fi.Extension;//获取图片类型

源文件: d:\localuser\ftp6247338\Web\picpage\xiangce_add.aspx.cs 行: 269

堆栈跟踪:

[SecurityException: 请求“System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”类型的权限已失败。]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) +31
System.Security.CodeAccessPermission.Demand() +46
System.IO.FileInfo.Init(String fileName, Boolean checkHost) +116
System.IO.FileInfo..ctor(String fileName) +45
picpage_xiangce_add.Button1_Click(Object sender, EventArgs e) in d:\localuser\ftp6247338\Web\picpage\xiangce_add.aspx.cs:269
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9615682
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6704
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +245
System.Web.UI.Page.ProcessRequest() +72
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +58
ASP.picpage_xiangce_add_aspx.ProcessRequest(HttpContext context) in App_Web_yfh1enol.2.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答