How can I intercept the HTML from a ViewResult, modify it and serve it up?

后端 未结 2 523
逝去的感伤
逝去的感伤 2021-01-14 03:21

I\'m writing a simple CMS.

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 (

2条回答
  •  一整个雨季
    2021-01-14 04:13

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

    • 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

    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

提交回复
热议问题