ASP.NET 网页中的 _PageStart.cshtml 与 _AppStart.cshtml
_PageStart.cshtml 与 _AppStart.cshtml 有什么区别?我可以互换使用它们吗?
What is the difference between _PageStart.cshtml vs _AppStart.cshtml? Can I use them interchangeably?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
_AppStart.cshtml 在应用程序首次启动时执行一次。它是设置全局变量或配置电子邮件等的地方。每次请求相同或较低级别文件夹中的页面时,_PageStart.cshtml 都会执行。它是执行每个请求处理的地方,例如设置布局页面或拒绝未经身份验证的用户访问文件夹。
请参阅 Microsoft 网站上的这篇文章页面站点。
由于它们在应用程序生命周期的不同时间执行,因此很难看出它们如何可以互换使用,无论您的意思是什么。
_AppStart.cshtml is executed once when the application first starts. It is the place for setting global variables, or configuring email etc. _PageStart.cshtml executes every time a page in the same or lower level folder is requested. It is the place for performing per-request processing, such as setting layout pages or denying access to a folder to unauthenticated users.
See this article at the Microsoft Web Pages site.
Since they execute at different times in the application's lifecycle, it's difficult to see how they can be used interchangeably, whatever you mean by that.