我正在使用实体框架创建一个 C# MVC4.5 项目,并在我的 Web.config 中设置了以下连接字符串:
<connectionStrings>
<add name="Entities"
connectionString="metadata=res://*/PersistenceModel.csdl|res://*/PersistenceModel.ssdl|res://*/PersistenceModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\sqlexpress;initial catalog=TravPro;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
然后我按如下方式访问此字符串:
string con = ConfigurationManager.ConnectionStrings["Entities"].ConnectionString;
WebSecurity.InitializeDatabaseConnection(con,
"UserProfile",
"UserId",
"UserName",
true);
这会引发“路径中的非法字符”异常:
[ArgumentException: Illegal characters in path.]
System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional) +10631190
System.IO.Path.Combine(String path1, String path2) +42
WebMatrix.Data.ConfigurationManagerWrapper.GetConnection(String name, Func`2 getConfigConnection, Func`2 fileExists) +208
WebMatrix.Data.ConfigurationManagerWrapper.GetConnection(String name) +91
WebMatrix.Data.Database.OpenNamedConnection(String name, IConfigurationManager configurationManager) +18
WebMatrix.Data.Database.Open(String name) +61
WebMatrix.WebData.DatabaseConnectionInfo.Connect() +42
WebMatrix.WebData.SimpleMembershipProvider.ConnectToDatabase() +25
WebMatrix.WebData.SimpleMembershipProvider.CreateTablesIfNeeded() +35
WebMatrix.WebData.WebSecurity.InitializeMembershipProvider(SimpleMembershipProvider simpleMembership, DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean createTables) +73
WebMatrix.WebData.WebSecurity.InitializeProviders(DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +51
WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(String connectionStringName, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +51
TravPro.Web.Filters.SimpleMembershipInitializer..ctor() in c:\Work\trunk\TravPro\TravPro.Web\Filters\InitializeSimpleMembershipAttribute.cs:43
有人可以协助并让我知道哪些字符需要转义或如何解决此异常?