我有一个非常奇怪的问题。我将MVC 4程序发布到IIS
C:\inetpub\wwwroot\AlvinCMS
,
但是当我从IIS运行程序(运行已发布的程序)时,代码仍以某种方式引用开发文件夹的路径
(C:\Users\Public\Documents\Projects\Alvin CMS Project\Alvin CMS\Alvin CMS
)。
当系统尝试使用此连接字符串附加数据库时,证明了这一点:
public static string CreateDefaultValueDBConnectionString()
{
const string dataSource = ".\\SQLEXPRESS";
const string initialCatalog = "AlvinCMS_Default";
const string attachedFileName = "AlvinCMS_Default.mdf";
SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();
sqlBuilder.DataSource = dataSource;
sqlBuilder.InitialCatalog = initialCatalog;
sqlBuilder.MultipleActiveResultSets = true;
sqlBuilder.IntegratedSecurity = true;
sqlBuilder.AttachDBFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data", "db", "backup", attachedFileName);
return sqlBuilder.ConnectionString;
}
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data", "db", "backup", attachedFileName);
始终以开发文件夹C:\Users\Public\Documents\Projects\Alvin CMS Project\Alvin CMS\Alvin CMS
为目标,而不是已发布的文件夹C:\inetpub\wwwroot\AlvinCMS
。另外,在尝试访问我的视图时,我总是会收到此错误
虚拟路径'/DynamicForm/LoginPartial.cshtml/'映射到另一个应用程序,这是不允许的
如何停止引用?
答案 0 :(得分:0)
您是否尝试使用Server.MapPath
代替AppDomain.CurrentDomain.BaseDirectory
?
sqlBuilder.AttachDBFilename = Path.Combine( Server.MapPath("~/App_Data/db/backup"), attachedFileName);