VS2010升级VS2012必备(MVC4 WebPage2.0 Razor2.0资料汇集)
刚把项目升级到2012,发现发生了很多变化,以下是最近看过的网站和资料汇集,供需要者参考。
本文在最近一个月可能会不断更新。
Razor2.0
WebPage2.0
MVC3到MVC4升级中遇到的问题汇总
登录机制换了,和用户相关的操作会出现一些错误
var users = new UsersContext().UserProfiles.ToList();
userContext.UserProfiles.Remove(user); userContext.SaveChanges();
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
并把它挪到(此语句只能调用一次,故需要挪动,或注释掉):
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); AuthConfig.RegisterAuth(); ... WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); }另外在一个叫做 FilterConfig.cs文件中,请加上第二句话:
public class FilterConfig { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); filters.Add(new InitializeSimpleMembershipAttribute()); } }原文见:http://stackoverflow.com/questions/12342398/simplemembership-mvc4-authorizeattribute-and-roles
Razor的一些小改动
@{ Layout = "~/Views/Shared/_Layout.cshtml"; }
Layout = "~/Views/Shared/_Layout.cshtml";这句话,在任何其他地方设置Layout可能会导致错误,但不报错!只是从此处以后的内容不再显示。
Layout = "~/Views/Shared/_Layout.cshtml";
LocalDB数据库升级
-
In Server Explorer, choose the Connect to Database button.
-
In the Add Connection dialog box, specify the following information:
-
Data Source: Microsoft SQL Server (SqlClient)
-
Server Name: (LocalDB)\v11.0
-
Attach a database file: Path, where Path is the physical path of the primary .mdf file.
-
Logical Name: Name, where Name is the name that you want to use with the file.
-
-
Choose the OK button.
-
When prompted, choose the Yes button to upgrade the file.
VS2010升级VS2012必备(MVC4 WebPage2.0 Razor2.0资料汇集),古老的榕树,5-wow.com
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。