_AppStart.cshtml中的当前上下文错误中不存在"WebSecurity"

san*_*nvj 1 asp.net razor asp.net-mvc-4

我收到以下编译错误:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0103: The name 'WebSecurity' does not exist in the current context

Source Error:


Line 1:  @{
Line 2:      if (!WebSecurity.Initialized)
Line 3:      {
Line 4:          WebSecurity.InitializeDatabaseConnection("AreaProject", "User", "UserId", "EmailAddress", autoCreateTables: true);

Source File: c:\Projects\area\trunk\dotNet\area.Web\area.Web\_AppStart.cshtml    Line: 2 
enter code here
Run Code Online (Sandbox Code Playgroud)

我的项目正确引用"System.Web",而我使用"System.Web.Security"的其他文件编译正常.

当我将引用System.Web,System.Web.Pages和System.Web.Razor添加到我的应用程序时,问题就出现了.但我没有对WebMatrix.WebData或WebMatrix.Data进行任何更改.

Ste*_*n V 5

此处引用的WebSecurity类是分开的,WebMatrix.WebData而不是System.WebSystem.Web.Security.您可能需要添加引用,WebMatrix.WebData.dll并且事情应该至少超过运行时编译器错误.

您在运行时遇到编译器错误,因为通常在应用程序第一次启动时编译视图,而不是在编译程序集时编译.