百度这些东西,还是会浪费了一些不必要的时间,记录记录以备后续
如果不在web.config中配置管道开关则伪静态无效
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
Microsoft.AspNet.Web.Optimization
BundleConfig.RegisterBundles(BundleTable.Bundles);
<modules runAllManagedModulesForAllRequests="true" />
,则序StyleBundle传递的虚拟路径可以包含后缀名.css/.js
<compilation debug="false" targetFramework="4.5" />
的debug值控制,或者在RegisterBundles方法中强制启用:BundleTable.EnableOptimizations = true;
public class FileController : Controller
{
private static readonly string[] ImageFileExtensions = GetConfigValue("ImgExts").Split(',') ?? new string[] { ".jpg", ".jpeg", ".gif", ".png", ".bmp", ".ico" };
private static readonly string ImageDomain = GetConfigValue("ImgDomain");//末尾不带/
private static readonly string UploadDir = GetConfigValue("UploadDir", "/uploads/");//相对路径吧
private static readonly int UploadMaxLength = int.Parse(GetConfigValue("UploadMaxLength", "5242880"));//默认最大5M
private static string GetConfigValue(string key, string def = "")
{
return System.Configuration.ConfigurationManager.AppSettings[key] ?? def;
}
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
if (file == null)
{
return Json(new
{
code = -1,
msg = "未上传任何东西!"
});
}
if (file.ContentLength > UploadMaxLength)
{
return Json(new
{
code = -1,
msg = "文件大小不能超过5M!"
});
}
string ext = Path.GetExtension(file.FileName);
if (ImageFileExtensions.Any(e => e == ext))
{
return Json(new
{
code = -1,
msg = "不支持此文件格式"
});
}
string fileName = Guid.NewGuid().ToString() + ext;
string saveDir = System.Web.HttpContext.Current.Request.MapPath(UploadDir);
if (!Directory.Exists(saveDir))
{
Directory.CreateDirectory(saveDir);
}
string savePath = Path.Combine(saveDir, fileName);
file.SaveAs(savePath);
return Json(new
{
code = 0,
msg = "上传成功",
data = new
{
src = ImageDomain + UploadDir + fileName,
title = ""
}
});
}
}
js //定义自己的规则 var myXssOptions = function (isEditer) { return { onTagAttr: function (tag, name, value, isWhiteAttr) { //保留style标签 默认会将style给干掉 if (name == 'style') { return "style='" + value + "'"; } //替换src为lay-src做懒加载 if (!isEditer && tag == 'img' && name == 'src') { return "lay-src='" + value + "'"; } } } };