如何从一个的ViewResult拦截HTML,修改和服务于它呢? [英] How can I intercept the HTML from a ViewResult, modify it and serve it up?

查看:197
本文介绍了如何从一个的ViewResult拦截HTML,修改和服务于它呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个简单的CMS。

I'm writing a simple CMS.

我希望能够加载一个视图,有它包含一个母版页里面,然后扫描HTML等等我可以取代一些自定义标签(如{{博客}}用我自己的博客输出),然后为它服务到浏览器中。

I want to be able to load a View, having it included inside a master page, and then scan the HTML so that I can replace some custom tags (like {{blog}} with my own blog output) and then serve it up to the browser.

我如何可以访问从的ViewResult以便在HTML拦截呢?

How can I get access to the HTML from the ViewResult in order to intercept it?

推荐答案

听起来像是你想要写的 ActionFilterAttribute 。此属性有以下方法:

Sounds like you want to write an ActionFilterAttribute. This attribute has the following methods:


  • OnActionExecuting - 执行饰行动之前名为

  • OnActionExecuted - 操作方法被调用后调用,但之前的ActionResult 被渲染
  • $ b。 $ b
  • OnResultExecuting - 结果呈现前callled

  • OnResultExecuted - 称为结果之后被渲染

  • OnActionExecuting - called just before the decorated action is executed
  • OnActionExecuted - called after the action method is called, but before the ActionResult is rendered.
  • OnResultExecuting - callled before the result is rendered
  • OnResultExecuted - called after the result is rendered

这里有一个例子,返回JSON或取决于内容类型标头的XML数据:使用ASP.NET MVC这充分说明双方JSON和纯XML

There is an example here which returns either JSON or XML data depending on the "Content-type" header: Create REST API using ASP.NET MVC that speaks both Json and plain Xml

这篇关于如何从一个的ViewResult拦截HTML,修改和服务于它呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆