简体   繁体   English

MVC一次性控制器

[英]MVC Single Use Controller

I have a 'Setup' view and associated controller which I use to configure the database and web.config of an MVC site immediately after cloning the site from source control. 我有一个“设置”视图和关联的控制器,从源代码控制中克隆站点后,可立即使用它来配置MVC站点的数据库和web.config。

Once it's been run once, I want to prevent the code in my 'Setup' controller method from ever being run again. 一旦运行一次,我想防止再次运行“设置”控制器方法中的代码。

Would programmatically deleting the 'Setup' view at the end of my 'Setup' controller method suffice, or is there a better approach? 在我的“设置”控制器方法末尾以编程方式删除“设置”视图是否足够,还是有更好的方法?

or is there a better approach? 还是有更好的方法?

Yes, in your Setup controller action check if the database is already created and if it is don't run the code, simply return some error or whatever. 是的,在安装程序控制器操作中检查是否已经创建了数据库,以及是否不运行该代码,只需返回一些错误或其他信息即可。

Basically the code will run only if whatever this code is doing is not yet done which you could determine programatically. 基本上,该代码仅在您尚未以编程方式确定的情况下执行,否则该代码将仅运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM