在使用mvc3.0项目中使用到了Telerik中Editor,做为编辑器很满意,按官方给的Demo也全部实现出来了功能使用也正常。使用vs2010运行后Editor功能全部能使(包括上传图片)。但是发布到服务器上之后,editor中其它功能都正常,唯独添加图片的时候会报'Error! The requested Url returned 500' -intenal server Error .哪位有用过editor功能是否遇到这种问题请问是如何解决的?
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Telerik.Web.Mvc.UI; using System.IO; using Com.Hospira.Sox.Utility; using log4net; namespace Com.Hospira.Controllers { public class ImageBrowserController : EditorFileBrowserController { private const string contentFolderRoot = "~/Content/"; private const string prettyName = "Editor/"; private static readonly string[] foldersToCopy = new[] { "~/Content/Editor" }; protected ILog logger = null; public ImageBrowserController() { logger = LogManager.GetLogger(this.GetType()); logger.Info("File Name : ImageBrowserController"); } public override string[] ContentPaths { get { return new[] { CreateUserFolder() }; } } private string UserID { get { var obj = Session[GlobalConstant.AUTHENTICATION_LOGINSESSIONKEY]; if (obj == null) { Session[GlobalConstant.AUTHENTICATION_LOGINSESSIONKEY] = obj = DateTime.Now.Ticks.ToString(); } return (string)obj; } } private string CreateUserFolder() { var userFolder = Path.Combine("TempFiles", UserID); var virtualPath = Path.Combine(contentFolderRoot, userFolder, prettyName); var path = Server.MapPath(virtualPath); logger.Info("Editor path" + path); try { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); foreach (var sourceFolder in foldersToCopy) { CopyFolder(Server.MapPath(sourceFolder), path); } } } catch (Exception ex) { logger.Error("ImageBrowserController.CreateUserFolder",ex); } return virtualPath; } private void CopyFolder(string source, string destination) { try { if (!Directory.Exists(destination)) { Directory.CreateDirectory(destination); } foreach (var file in Directory.EnumerateFiles(source)) { var dest = Path.Combine(destination, Path.GetFileName(file)); System.IO.File.Copy(file, dest); } foreach (var folder in Directory.EnumerateDirectories(source)) { var dest = Path.Combine(destination, Path.GetFileName(folder)); CopyFolder(folder, dest); } } catch(Exception ex) { logger.Error("ImageBrowserController.CopyFolder",ex); } } } }
看看是不是上传目录的写入权限有问题
不是这个问题,因为我尝试过在服务上写文件是能生成的
这个功能最后启用了用脚本写的另外一个编辑器。这个为什么会出错的原因。可能是和我的项目哪有冲突。