200 OK真的表示没有问题吗?
有时候Status 200做为WebAPI的返回值,并不表示真的OK,例如取得一个文件,没有取到,可是返回值也会是200。
200只是表示一个WebAPI执行完毕,没有异常而已,并不表示确定成功。javascript
IIS7.0 上传文件失败,返回404。
乍一看是资源没法找到,实际上是设定问题,上传文件的最大长度限制,还须要下面这样的配置。
maxRequestLength不少文章都提到了,maxAllowedContentLength则不少文章没有提到。css
<configuration> <system.web> <compilation debug="true" targetFramework="4.5" /> <!--maxRequestLength就是文件的最大字符数,最大值不能超过2个G左右,executionTimeout是超时时间--> <httpRuntime targetFramework="4.5" maxRequestLength="1073741824" executionTimeout="3600" /> </system.web> <system.webServer> <security> <requestFiltering> <!--修改服务器容许最大长度--> <requestLimits maxAllowedContentLength="1073741824"/> </requestFiltering> </security> </system.webServer> </configuration>
使用了ReSharp的移除没有使用(Remove Unused Reference)的引用以后,Package项目配置文件中的一些Item会被删除掉,在项目发布的时候一些动态连接库不会被发布到BIN目录下面,致使如下这样的问题html
未能加载文件或程序集“Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或它的某一个依赖项。系统找不到指定的文件。
因此通常建议在使用ReSharp以前将项目进行CheckIn,若是出现特殊状况则执行Redo便可。
(具体配置文件:packages.config)java
<?xml version="1.0" encoding="utf-8"?> <packages> <package id="Antlr" version="3.5.0.2" targetFramework="net451" /> <package id="bootstrap" version="3.3.6" targetFramework="net451" /> <package id="CommonMark.NET" version="0.11.0" targetFramework="net451" /> <package id="Elasticsearch.Net" version="2.1.1" targetFramework="net451" /> <package id="jQuery" version="2.2.2" targetFramework="net451" /> <package id="jQuery.Validation" version="1.15.0" targetFramework="net451" /> <package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net461" /> <package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net461" /> <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net461" /> <package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net451" /> <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net451" /> <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net451" /> <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net451" /> <package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net461" /> <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.1" targetFramework="net451" /> <package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.3" targetFramework="net461" /> <package id="Microsoft.Net.Compilers" version="2.0.0-beta1" targetFramework="net451" developmentDependency="true" /> <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net461" /> <package id="Modernizr" version="2.8.3" targetFramework="net451" /> <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net451" /> <package id="NPOI" version="2.1.3.1" targetFramework="net451" /> <package id="Respond" version="1.4.2" targetFramework="net451" /> <package id="ThoughtWorks.QRCode" version="1.1.0" targetFramework="net451" /> <package id="WebGrease" version="1.6.0" targetFramework="net451" /> </packages>
因为安全上的缘由,Asp.net中QueryString等不容许出现<> 这样的字符
若是你确认的确须要跳过安全验证,里面最简单的解决方法是使用Unvalidated版本react
string strArticalID = context.Request.Unvalidated.Form["ArticalID"];
Asp.net MVC在运行的时候,会将全部Bin下面的DLL进行解析,若是有一个旧的DLL,例如是更名前的DLL残留在Bin目录中,则会出现多个同名控制器的问题。(在VS中怎么检查都不会发现这个问题的!)jquery
参见RouteConfig的编写,这里能够指定默认的Area,写法必须严格按照例子.
Home_Default这个路由名字不要使用(可能系统会默认注册这个名字)
(错误信息:路由集合中已存在名为“Home_default”的路由。路由名称必须惟一。)css3
若是不指定Layout,默认使用 Views/Shared/_Layout(_ViewStart.cshtml)git
组件放在Shared/DisplayTemplate/ 下面github
这是个浏览器兼容性的话题。有时候你会发现HTML的Class名称大小写写错了,样式也会生效,这是由于你没有加上 DOCTYPE 这个TAG。若是加上以后,则类名称不容许忽略大小写。web
修改Area名称后注意各处名字空间的统一
<system.web.webPages.razor> <pages pageBaseType="System.Web.Mvc.WebViewPage"> <namespaces> <add namespace="System.Web.Mvc" />
public ActionResult Index(int PageNo = 1)
*若是同时存在 没有参数和带参数的,会报错。可选参数倒没有问题。。。
可使用 $.post来简化Post操做
添加 IRequiresSessionState 接口便可
public class PublishPost : IHttpHandler, IRequiresSessionState
注意 forms的下标
注意 POST方法必须写明
<div class="SingleBox"> <a href="/Admin/Accept?ArticalID=@Model.ArticalInfo.Sn" class="btn btn-sm btn-success" onclick="return OpenModal(this.href, '确认接受', '确认接受该条记录?')"> <span class="glyphicon glyphicon-remove"> 接受 </span> </a> <br /><br /> <form action="/Admin/Reject" method="post"> <a href="javascript:document.forms[2].submit();" class="btn btn-sm btn-danger" onclick="return OpenModal(this.href, '确认拒绝', '确认拒绝该条记录?')"> <span class="glyphicon glyphicon-remove"> 拒绝 </span> </a> 审核留言: <input type="text" name="message" style="width:400px" /> <input type="hidden" name="ArticalID" value="@Model.ArticalInfo.Sn" /> </form> </div>
document.getElementById("ReplySubmit_" + PreViewReplyId).style.display = "none";
Bootstrap的btn-primary 可能有Submit的功能(待验证)
许多对于Stream的操做都会致使流的位置到EOS,或者整个流的被使用完了(没法复用?)
Jquery Wrap,能够给元素增长父元素。。。。。强大啊。。。
$(document).ready(function () { $(".PostBody img").wrap( function () { var filepath = this.src; var imagefilename = filepath.substring(_urlstr.length + "/FileSystem/Thumbnail?filename=".length) @{ string Image = ConfigurationManager.AppSettings["Image"]; string jsCode = string.Empty; if (Image == "QiNiu") { jsCode = "filepath = '" + @ConfigurationManager.AppSettings["URLBASE"] + "' + imagefilename;"; }else { jsCode = "filepath = '/FileSystem/Image?filename=' + imagefilename;"; } } @MvcHtmlString.Create(jsCode) //原图是外部链接的处理 if (this.src.indexOf("/FileSystem/Thumbnail") == -1){ if (this.src.indexOf("@ConfigurationManager.AppSettings["URLBASE"]") == -1){ filepath = this.src; } } return "<div class='imgArea'><a href='" + filepath + "'></a></div>" } );
使用特性:
/// <summary> /// 建立时间 /// </summary> [BsonDateTimeOptions(Kind = DateTimeKind.Local)] public DateTime CreateDateTime;
使用转换规则
BsonSerializer.RegisterSerializer(typeof(DateTime), new DateTimeSerializer(DateTimeKind.Local));
也能够IgnoreExtraElementsConvention忽略数据中有,可是数据模型中没有的字段。例如数据模型更名以后,数据库里面的残留字段。
pack.Add(new IgnoreExtraElementsConvention(true)); pack.Add(new IgnoreIfNullConvention(true));
属性,公共变量 序列化
静态变量,const 不序列化
using Newtonsoft.Json; var result = new { success = 1, message = "提示的信息,上传成功或上传失败及错误信息等。", url = filename }; string json = JsonConvert.SerializeObject(result); context.Response.Write(json);
new HttpPostedFileWrapper(file) as HttpPostedFileBase
dynamic obj = JsonConvert.DeserializeObject(sr.ReadToEnd());
<script type="text/javascript" src="http://tsi.github.io/jQuery.imgBox/imgBox/jquery.imgbox.js"></script> <link rel="stylesheet" href="http://tsi.github.io/jQuery.imgBox/imgBox/imgbox.css" /> <script> $(document).ready(function () { $(".PostBody img").wrap( function(){ return "<div class='imgArea'><a href='" + this.src + "'></a></div>" } ); $(".PostBody .imgArea a").imgbox({ slideshow: false }); }); </script>
IMongoQuery tagNameQuery = Query.EQ(nameof(TagName),tag);
Distinct对于数组的处理,是拆开数组项目,进行Distinct!!!!
使用In表示两个数组是否存在交集(由于In的相等,对于数组是拆开判断的)
Linq能够作不少强大的工做
x.GroupBy((article) => article.OwnerId).Select(group => new { ownerId = group.Key, Count = group.Count() });
修更名字的时候,须要同时修改View MarkUp的代码
/// <summary> /// 缩略图(JPEG) /// </summary> /// <param name="filename"></param> /// <returns></returns> [OutputCache(Duration = int.MaxValue)] public ActionResult Thumbnail(string filename) { var stream = new MemoryStream(); string Thumbnail = ConfigurationManager.AppSettings["Thumbnail"]; switch (Thumbnail) { case "Mongo": MongoStorage.GetFile(stream, filename, "Thumbnail"); break; case "FileSystem": stream = FileSystemStorage.GetFile(filename, "Thumbnail"); break; case "QiNue": //实际上这里直接使用QiNue的URL就能够了 stream = QiniuStorage.GetFile(filename); break; } return File(stream.ToArray(), "image/jpeg"); }
BsonSerializer.Deserialize<Article>(doc)
缘由是系统不知道如何进行分词,可使用第三方的分词组件
http://pandao.github.io/editor.md/
打开源代码能够看到全部的可配置项目
<script src="~/Content/editormd/editormd.min.js"></script> <link rel="stylesheet" href="~/Content/editormd/css/editormd.css" />
font文件夹也必须,否则部分图标缺失
Install-Package CommonMark.NET
图片上传等功能须要使用这个Plugins文件夹里面的插件
防止自动得到焦点,页面开始时候垂直位置不正确
因为缩放问题形成的,CSS里面12px,若是缩放以后,系统仍是维持原来的字体大小,整个字体在渲染的时候进行放大处理