探索ASP.NET网页-仅使用Razor的功能齐全的MiniBlog

ASP.NET "Razor" Web Pages are ASP.NET sites without models, views, controllers, or project files. Some folks say "oh, that's just Classic ASP, or PHP right? Not at all. It's the full power and speed of the .NET CLR, the full syntax of C#, LINQ, along with things like C# dynamics. It's super powerful, and my friend Mads and I are surprised more people don't use them for small things.

ASP.NET“剃刀”网页是没有模型,视图,控制器或项目文件的ASP.NET网站。 有些人说:“哦,那是Classic ASP还是PHP,对吗?完全没有。这是.NET CLR的全部功能和速度,C#,LINQ的全部语法以及C#动态特性。它超​​级强大,和我的朋友Mads和我感到惊讶的是,更多的人没有将它们用于小物件。

In fact, Rob Conery and I did the http://thisdeveloperslife.com web site using just Razor and Rob's "massive" micro-ORM. Later I made http://hanselminutes.com with Web Pages as well.

实际上,Rob Conery和我只是使用Razor和Rob的“大规模”微型ORM来创建http://thisdeveloperslife.com网站。 后来我也通过网页制作了http://hanselminutes.com

This blog runs DasBlog, an older ASP.NET 2.0 blogging engine I worked on with Clemens Vasters and a lot of co-contributors, but I'm actively checking on Mads' MiniBlog, a minimal but VERY competent blog engine using Razor Web Pages. Why wouldn't I use something like Ghost? I've thought about it, but MiniBlog is SO minimal and that makes it very attractive.

该博客运行DasBlog ,这是我与Clemens Vasters合作的较旧的ASP.NET 2.0博客引擎,并与许多共同撰稿人合作,但是我正在积极研究Mads的MiniBlog ,这是一个使用Razor Web Pages的最小但非常有效的博客引擎。 我为什么不使用Ghost之类的东西? 我已经考虑过了,但是MiniBlog非常简单,这使其非常有吸引力。

Here's some things I like about MiniBlog, as both a blog and a learning tool.

这是我喜欢MiniBlog的一些东西,既是博客又是学习工具。

最小的 (Minimal)

It's not called Mini for fun. There's a truly minimal packages.config of dependencies:

它不是叫Mini的乐趣。 真正的依赖项packages.config最少:

<packages>
<package id="AjaxMin" version="5.2.5021.15814" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="xmlrpcnet" version="3.0.0.266" targetFramework="net45" />
<package id="xmlrpcnet-server" version="3.0.0.266" targetFramework="net45" />
</packages>

干净使用Web服务处理程序 (Clean use of Handlers for Web Services)

Blogs do more than just serve pages, there is also a need for RSS feeds, MetaWeblog Web Services for things like Windows Live Writer, and dynamic minification for JS and CSS.

博客不仅为页面提供服务,还需要RSS提要,用于Windows Live Writer之类的MetaWeblog Web服务以及用于JS和CSS的动态最小化。

<handlers>
<add name="CommentHandler" verb="*" type="CommentHandler" path="/comment.ashx"/>
<add name="PostHandler" verb="POST" type="PostHandler" path="/post.ashx"/>
<add name="MetaWebLogHandler" verb="POST,GET" type="MetaWeblogHandler" path="/metaweblog"/>
<add name="FeedHandler" verb="GET" type="FeedHandler" path="/feed/*"/>
<add name="CssHandler" verb="GET" type="MinifyHandler" path="*.css"/>
<add name="JsHandler" verb="GET" type="MinifyHandler" path="*.js"/>
</handlers>

MiniBlog uses .ashx (HttpHanders) and wires them up in web.config. RSS feeds are easily handled with System.ServiceModel.Syndication, even JavaScript and CSS minification. Though MiniBlog is very new, it uses the old but extremely reliable CookComputing.XmlRpc for the MetaWeblog service communication with Windows Live Writer. I

MiniBlog使用.ashx(HttpHanders)并将其连接到web.config。 RSS Feed可以通过System.ServiceModel.Syndication轻松处理,甚至可以简化JavaScript和CSS 。 尽管MiniBlog是非常新的,但它使用旧的但极其可靠的CookComputing.XmlRpc与Windows Live Writer进行MetaWeblog服务通信。 一世

无需数据库(No Database Need)

I like apps that can avoid using databases. Sometimes the file system is a fine database. I thought this when we worked on DasBlog, Mads thought it when he made BlogEngine.NET (his original blog engine) and that "no database needed" design tenet continues with MiniBlog. It stores its files in XML, but MiniBlog could just as easily use JSON.

我喜欢可以避免使用数据库的应用程序。 有时文件系统是一个很好的数据库。 当我们在DasBlog上工作时,我以为是这样,Mads在他制作BlogEngine.NET(他的原始博客引擎)时就以为如此,而MiniBlog的“不需要数据库”的设计宗旨继续存在。 它以XML格式存储文件,但MiniBlog可以轻松使用JSON。

干净的内容可编辑设计服务 (Clean Content-Editable Design Service)

I always (exclusively) use Windows Live Writer for my blog posts. WLW is also the preferred way to write posts with MiniBlog. However, if you insist, MiniBlog also has a really nice content-editable scheme with a great toolbar, all in the browser:

我总是(专有地)将Windows Live Writer用于我的博客文章。 WLW也是使用MiniBlog撰写帖子的首选方式。 但是,如果您坚持认为,MiniBlog在浏览器中也有一个非常不错的内容可编辑方案,带有强大的工具栏:

Nice Editing Experience

When you are viewing a post while logged in as Admin, you click Edit and turn the page into editable content.

以管理员身份登录时,在查看帖子时,单击“编辑”,然后将页面变成可编辑的内容。

editPost = function () {
txtTitle.attr('contentEditable', true);
txtContent.wysiwyg({ hotKeys: {}, activeToolbarClass: "active" });
txtContent.css({ minHeight: "400px" });
txtContent.focus();

btnNew.attr("disabled", true);
btnEdit.attr("disabled", true);
btnSave.removeAttr("disabled");
btnCancel.removeAttr("disabled");
chkPublish.removeAttr("disabled");

showCategoriesForEditing();

toggleSourceView();

$("#tools").fadeIn().css("display", "inline-block");
}

The resulting HTML you write (in a WYSIWYG mode) is converted into XHTML and posted back to MiniBlog:

您编写的结果HTML(以WYSIWYG模式)将转换为XHTML并发布回MiniBlog

parsedDOM = ConvertMarkupToValidXhtml(txtContent.html());

$.post("/post.ashx?mode=save", {
id: postId,
isPublished: chkPublish[0].checked,
title: txtTitle.text().trim(),
content: parsedDOM,
categories: getPostCategories(),
})

The JavaScript is surprisingly simple, and gets one thinking about adding basic editing and CMS functions to websites. A design mode would be a daunting task 5 years ago, and with today's JavaScript it's almost trivial.

JavaScript非常简单,并且想到了向网站添加基本编辑和CMS功能的想法。 5年前,设计模式将是一项艰巨的任务,而对于当今JavaScript来说,这几乎是微不足道的。

It even automatically optimizes images you drag and drop into the design surface and upload.

它甚至可以自动优化拖放到设计图面并上载的图像。

public static string SaveFileToDisk(byte[] bytes, string extension)
{
string relative = "~/posts/files/" + Guid.NewGuid() + "." + extension.Trim('.');
string file = HostingEnvironment.MapPath(relative);

File.WriteAllBytes(file, bytes);

var cruncher = new ImageCruncher.Cruncher();
cruncher.CrunchImages(file);

return VirtualPathUtility.ToAbsolute(relative);
}

The code is fun to read, and you can go check it out at https://github.com/madskristensen/MiniBlog. It supports HTML5 microdata, sitemaps, both RSS and Atom, simple theming, and gets a 100/100 of Google Page Speed.

该代码很有趣,可以在https://github.com/madskristensen/MiniBlog上进行检查。 它支持HTML5微数据,站点地图,RSS和Atom,简单的主题设置,并获得100/100的Google Page Speed。

翻译自: https://www.hanselman.com/blog/exploring-aspnet-web-pages-a-fullyfeatured-miniblog-using-just-razor

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值