我项目在国内的服务器上上传图片没有问题!但是放到Godaddy的服务器上就不能上传图片!起初我以为是权限问题,后来用一个木马程序自己上传图片,发现图片能上传上去,这样就说明上传图片是有权限的,然后根据传图片报的异常测试,得出的结论是:原程序上传图片的路径不对!
我改了N多种路径都不正确,无奈之中只能上CSDN上来请教高手了!上传的方法代码我就不多贴出来了。只贴上传文件路径好了!图片都是从本地上传到服务器上:
一下变量意思如下: webFilePath为服务器路径名 fileName为图片名称。在国内服务器上写:string webFilePath_s = Server.MapPath("../newsImg/miniature/" + fileName); 成功!放在Godaddy上不行。
于是我用了以下两种种方法全不行,但在本地这样写都能正常运行!!文件夹写入权限已经给了!
string webFilePath_s = Server.MapPath("24xinwen/newsImg/miniature/" + fileName);
绝对路径方式:string webFilePath_s = "d:\\hosting\\cokele1008\\24xinwen\\newsImg\\miniature\\ " + fileName; 这个是我空间服务器路径:
图片所在绝对路径: d:\hosting\cokele1008\24xinwen\newsImg\miniature
图片所在相对路径: /24xinwen/newsImg/miniature/我是想把图片上传到服务器上的/newsImg/miniature/中去! 项目放在/24xinwen文件夹的根目录下 域名也是绑定在/24xinwen目录上。
请问我该怎么写才能正确的上传图片? 一下附带上传图片的异常信息! 报的异常时没有权限,但是用木马程序可以上传图片,当图片的路径不正确时就会报下面的异常,所以我断定我项目的程序是因为上传图片路径不对! 国内服务器上能正常运行上传.切用的控件是VS 2005上自带的UploadField控件,所以应该不存在控件不支持问题!
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.Source Error:
[No relevant source lines]
Source File: App_Web_mahgjhqf.5.cs Line: 0 Stack Trace:
[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
Manager_Manage_news.Button1_Click(Object sender, EventArgs e) +1256
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
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) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
System.Web.UI.Page.ProcessRequest() +80
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.xinwen_edit_news_aspx.ProcessRequest(HttpContext context) in App_Web_mahgjhqf.5.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
我改了N多种路径都不正确,无奈之中只能上CSDN上来请教高手了!上传的方法代码我就不多贴出来了。只贴上传文件路径好了!图片都是从本地上传到服务器上:
一下变量意思如下: webFilePath为服务器路径名 fileName为图片名称。在国内服务器上写:string webFilePath_s = Server.MapPath("../newsImg/miniature/" + fileName); 成功!放在Godaddy上不行。
于是我用了以下两种种方法全不行,但在本地这样写都能正常运行!!文件夹写入权限已经给了!
string webFilePath_s = Server.MapPath("24xinwen/newsImg/miniature/" + fileName);
绝对路径方式:string webFilePath_s = "d:\\hosting\\cokele1008\\24xinwen\\newsImg\\miniature\\ " + fileName; 这个是我空间服务器路径:
图片所在绝对路径: d:\hosting\cokele1008\24xinwen\newsImg\miniature
图片所在相对路径: /24xinwen/newsImg/miniature/我是想把图片上传到服务器上的/newsImg/miniature/中去! 项目放在/24xinwen文件夹的根目录下 域名也是绑定在/24xinwen目录上。
请问我该怎么写才能正确的上传图片? 一下附带上传图片的异常信息! 报的异常时没有权限,但是用木马程序可以上传图片,当图片的路径不正确时就会报下面的异常,所以我断定我项目的程序是因为上传图片路径不对! 国内服务器上能正常运行上传.切用的控件是VS 2005上自带的UploadField控件,所以应该不存在控件不支持问题!
Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.Source Error:
[No relevant source lines]
Source File: App_Web_mahgjhqf.5.cs Line: 0 Stack Trace:
[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
Manager_Manage_news.Button1_Click(Object sender, EventArgs e) +1256
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
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) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
System.Web.UI.Page.ProcessRequest() +80
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.xinwen_edit_news_aspx.ProcessRequest(HttpContext context) in App_Web_mahgjhqf.5.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
解决方案 »
- Asp.net 配置到IIS
- 问题终于找到了!!
- 我快被这个问题逼疯了,高分求解
- 新闻正则高手来
- 如何利用树进行权限管理,请高手赐教
- 在OWC中怎么画一条线呢,怎么给它添加颜色呢?
- 在JavaScript代碼中如果取得某個TreeView節點的父節點!(JS代碼)解決後就結貼。
- 请教思路:小弟想做这么一个功能,能实时查看系统当前所有在线人员
- 高分:我怎么让DATAGRID的日期字段只显示日期,不显示时间??数据库里只存放了日期没有时间啊
- 运行aspx页面出现“'object' is defined in multiple places; using definition from 'C:\winnt\microsoft.net\framework\v1.0.3705\msco
- ASP.net引用CSS文件相关问题
- 本人的一个网站最新上线,但有些问题,请大家指点指点啊!
{
string imgpath1 = string.Empty;
string fileContentType = fu.PostedFile.ContentType;
if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg")
{
Stream name = fu.PostedFile.InputStream;
string file_name = fu.PostedFile.FileName;// 客户端文件路径
Random rand = new Random(1000);
FileInfo file = new FileInfo(file_name);
string fileExtension = System.IO.Path.GetExtension(file_name);
string fileName = System.DateTime.Now.Ticks.ToString() + rand.Next(9999).ToString() + fileExtension; //生成新的图片文件名
// string webFilePath_s = Server.MapPath("/24xinwen/newsImg/miniature/" + fileName); // 服务器端缩略图路径
// string webFilePath_s =Request.PhysicalApplicationPath +("newsImg\\miniature\\ " + fileName); // 服务器端缩略图路径 string webFilePath_s = "d:\\hosting\\cokele1008\\24xinwen\\newsImg\\miniature\\ " + fileName; // 服务器端缩略图路径
if (!File.Exists(webFilePath_s))
{
try
{
System.Drawing.Image originalImage = System.Drawing.Image.FromStream(name);
originalImage.Save(webFilePath_s);
imgpath1 = "newsImg/miniature/" + fileName;//取得图路径
originalImage.Dispose();
}
catch (Exception ex)
{
((Label)Page.FindControl("Label2")).Text = "提示:文件上传失败,失败原因:" + ex.Message;
}
}
else
{
((Label)Page.FindControl("Label2")).Text = "提示:文件已经存在,请重命名后上传";
}
}
else
{
((Label)Page.FindControl("Label2")).Text = "提示:文件类型不符";
}
return imgpath1;
}这个是上传代码
木马是管理员帐号运行的当然可以
网页是asp.net帐号所以不行
d:\hosting\cokele1008\24xinwen\newsImg\miniature\ 图片名
这样能把图片上传上去! 说明上传图片的权限是有的! 而且通过这种方法能把图片上传到其他有写入权限的目录中去!
如果目录不存在就会报上面的异常! 所以应该不是权限问题了
貌似木马类的取得权限都是administrators这样的权限吧(或者写入方法跟asp.net写入文件夹的方法不一样)
asp.net运行的的没有这个权限高。
你在你那个上传的目录上盖users组权限 给一个写入权限应该就可以了。
控制面板里面好像不能设置IIS上的权限,只有一个文件夹读,写权限!
Using a Medium trust level prеvents aрpliсаtion frоm accessing shared system resources and eliminates the potential for application interference. Adding OleDbPermission and OdbcPermission allows applications to use those data providers to access databases. WebPermission is modified to allow outbound http and https traffic.Please let us know if we can assist you in any other way.Regards,Andrea P.
Online Support Representative