[{"data":1,"prerenderedAt":246},["ShallowReactive",2],{"navigation":3,"post-\u002Fposts\u002F2016\u002Fasp-net-core-first-experience":20,"surroundPosts-\u002Fposts\u002F2016\u002Fasp-net-core-first-experience":233},[4,8,12,16],{"title":5,"path":6,"stem":7},"首页","\u002F","00.index",{"title":9,"path":10,"stem":11},"文章","\u002Fposts","01.posts",{"title":13,"path":14,"stem":15},"动态","\u002Fmoments","02.moments",{"title":17,"path":18,"stem":19},"关于","\u002Fabout","09.about",{"id":21,"title":22,"body":23,"class":214,"cover":214,"coverSize":214,"date":215,"description":29,"draft":216,"extension":217,"hideComments":216,"location":214,"meta":218,"navigation":219,"path":220,"readingTime":221,"seo":226,"sitemap":227,"stem":228,"tags":229,"time":214,"weather":214,"__hash__":232},"posts\u002Fposts\u002F2016\u002F20160721.asp-net-core-first-experience.md","ASP.NET Core 初体验",{"type":24,"value":25,"toc":212},"minimark",[26,30,51,75,78,96,99,141,190,208],[27,28,29],"p",{},"前两天试了下 ASP.NET Core MVC，很好用。微软整合了大量前端工具，npm、Bower 都可以很方便地使用了，甚至对 Grunt、Gulp 这类的工具都有集成一些任务管理器，这对前端来说，是一件鼓舞人心的事。",[27,31,32,33,37,38,40,41,43,44,46,47,50],{},"ASP.NET Core MVC 的推荐目录结构也进行了调整，新增了",[34,35,36],"code",{},"wwwroot","这样一个静态目录，js、css、图片都可以放这里面，而 Bower 管理的第三方前端库则会自动下载到",[34,39,36],{},"里面的 lib 目录下。作为强迫症的我，",[34,42,36],{},"这个目录必须全部是自动生成的。通过 Gulp，可以很轻松的实现这一点。继承原先的目录结构习惯，在解决方案下建立 Scripts、Styles、Images 文件夹，里面用来放原始的 js、less 和图片，然后通过 Gulp 进行合并、压缩、复制到",[34,45,36],{},"目录下，这样 wwwroot 这个目录就可以在 git 里面排除掉了。完美。而在 ASP.NET Core 的项目目录下默认的",[34,48,49],{},".gitignore","文件里，微软其实是已经有这样的想法：",[52,53,58],"pre",{"className":54,"code":55,"language":56,"meta":57,"style":57},"language-log shiki shiki-themes material-theme-lighter github-light github-dark","# Uncomment if you have tasks that create the project's static files in wwwroot\n#wwwroot\u002F\n","log","",[34,59,60,69],{"__ignoreMap":57},[61,62,65],"span",{"class":63,"line":64},"line",1,[61,66,68],{"class":67},"su5hD","# Uncomment if you have tasks that create the project's static files in wwwroot\n",[61,70,72],{"class":63,"line":71},2,[61,73,74],{"class":67},"#wwwroot\u002F\n",[27,76,77],{},"在代码层面，和之前差别不大，基本上 M、V、C 的代码都可以直接拿过来用。在 bundle 上有一些变化，然而我是直接删掉了默认的 bundle 配置，既然可以方便地使用 Gulp 了，为啥不用呢？",[27,79,80,81,84,85,87,88,91,92,95],{},"在 View 中，新增了",[34,82,83],{},"environment","的语法，可以通过",[34,86,83],{},"标签来控制开发环境和生产环境的不同输出，主要是用来控制 css、js 这些文件的引用，在开发环境下使用未压缩的文件，在生产环境下使用压缩过的文件。还提供了 cdn 的方式，可以配置多个链接，优先使用 CDN 的链接，通过",[34,89,90],{},"asp-fallback-test","来检查 CDN 的链接是否可用，不可用的话再切换为本地的链接。和之前 Bundle 里面的方式差不多，只是使用起来更简单了。现在 css、js 这些文件的缓存控制也比以前更简单，只需要加上",[34,93,94],{},"asp-append-version=\"true\"","即可在文件名后面自动加上版本号后缀。",[27,97,98],{},"项目部署上面，确实遇到了一个坑。我是通过 Web Deploy 来自动部署的，花了半天时间才终于搞定。",[100,101,102,110,132,138],"ol",{},[103,104,105,106,109],"li",{},"IIS 里应用程序池中的",[34,107,108],{},".NET CLR","版本要选择“无托管代码”",[103,111,112,113,116,117,120,121,124,125,128,129,131],{},"安装",[34,114,115],{},".NET Core Windows Server Hosting","，这里有个大坑，安装完之后要执行一下",[34,118,119],{},"iisreset","，我没有执行这一步，导致出现了",[34,122,123],{},"HTTP Error 502.5 - Process Failure","的问题，从事件查看器里面看到的错误日志是：",[34,126,127],{},"Failed to start process with commandline '\"dotnet\" .\\****.dll', ErrorCode = '0x80070002'.","。遇到同样问题的朋友可以试试",[34,130,119],{},"或者重启机器。",[103,133,112,134,137],{},[34,135,136],{},"HttpPlatformHandler","。",[103,139,140],{},"还有个就是我当时用 Web Delpoy 往服务器部署的时候，文件总是推不上去，后来 Google 了一下，在 pubxml 里面加上了以下两行：",[52,142,146],{"className":143,"code":144,"language":145,"meta":57,"style":57},"language-xml shiki shiki-themes material-theme-lighter github-light github-dark","\u003CAllowUntrustedCertificate>True\u003C\u002FAllowUntrustedCertificate>\n\u003CUsePowerShell>False\u003C\u002FUsePowerShell>\n","xml",[34,147,148,172],{"__ignoreMap":57},[61,149,150,154,158,161,164,167,169],{"class":63,"line":64},[61,151,153],{"class":152},"sP7_E","\u003C",[61,155,157],{"class":156},"sQzsp","AllowUntrustedCertificate",[61,159,160],{"class":152},">",[61,162,163],{"class":67},"True",[61,165,166],{"class":152},"\u003C\u002F",[61,168,157],{"class":156},[61,170,171],{"class":152},">\n",[61,173,174,176,179,181,184,186,188],{"class":63,"line":71},[61,175,153],{"class":152},[61,177,178],{"class":156},"UsePowerShell",[61,180,160],{"class":152},[61,182,183],{"class":67},"False",[61,185,166],{"class":152},[61,187,178],{"class":156},[61,189,171],{"class":152},[100,191,193],{"start":192},5,[103,194,195,196,203,204,207],{},"下载",[197,198,202],"a",{"href":199,"rel":200,"title":202},"https:\u002F\u002Fgithub.com\u002Faspnet\u002FDataProtection\u002Fblob\u002Fdev\u002FProvision-AutoGenKeys.ps1",[201],"nofollow","Provisioning PowerShell script","，在服务器上使用",[34,205,206],{},"PowerShell","运行，输入应用程序池的名称即可。",[209,210,211],"style",{},"html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sQzsp, html code.shiki .sQzsp{--shiki-light:#E53935;--shiki-default:#22863A;--shiki-dark:#85E89D}",{"title":57,"searchDepth":71,"depth":71,"links":213},[],null,"2016-07-21",false,"md",{},true,"\u002Fposts\u002F2016\u002Fasp-net-core-first-experience",{"text":222,"minutes":223,"time":224,"words":225},"4 min read",3.695,221700,739,{"title":22,"description":29},{"loc":220},"posts\u002F2016\u002F20160721.asp-net-core-first-experience",[230,231],"技术",".NET","R33Y8oAf52Ae4S4ZF29eR7LlxZpXApb2LypHiBQIWSw",[234,240],{"title":235,"path":236,"stem":237,"date":238,"description":239,"children":-1},"“Bad Request - Invalid Hostname” 的解决办法","\u002Fposts\u002F2016\u002Fbad-request-invalid-hostname","posts\u002F2016\u002F20160731.bad-request-invalid-hostname","2016-07-31","最近在做一个微信端的应用，除了在本地测试之外，有时候还需要在手机上进行测试。",{"title":241,"path":242,"stem":243,"date":244,"description":245,"children":-1},"使用 Travis CI 自动部署 Hexo","\u002Fposts\u002F2016\u002Fhexo-with-travis-ci","posts\u002F2016\u002F20160719.hexo-with-travis-ci","2016-07-19","先占个坑，有空写教程。",1777580285255]