开发者

Parse all Views for a specific Tag

I use a homebrewn CMS in my site. The texts in it are used by inserting an html-helper into the view:

<%=Html.CmsEntry("About.Title")%>

The entries of the CMS are stored in SQLServer. I need a way to scan all views in my project and see if all tokens are already in the database.

Is there a way to do this? I already enter an entry into the DB at runtime, when a token is not开发者_开发技巧 found, but I need a way to do this without visiting each page. Maybe via reflection?


One way to do this is to create a page (controller action) that scans through the files looking for "Html.CmsEntry" and parses out the page names, and then queries the database.

If you have access to the database from your dev machine, you could possible do this in a console app, and set it as a build action, so whenever you compile, it runs.

Failing that, you could try relying on a spider (GoogleBot, or otherwise) to hit all your pages, and trigger your existing logging code.

Alternatively, you could store all your page names as constants or enum values. If you used enum values, you could easily spin through them (using Enum.GetValues) and check they're in the database.

All that said, if the pages are stored in your database, can't you do away with all the static pages that call them, and generate everything dynamically from the content already in the database?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜