【发布时间】:2013-08-21 16:54:54
【问题描述】:
我在尝试引用导入到空白项目中的项目中的方法/类时遇到了困难。重新创建它的确切步骤如下
- 下载并解压到一个临时文件夹http://mywsat.codeplex.com/
- 在 VS - Asp.Net Empty Web Application .NET 3.5 中创建一个名为 WebApplication1 的新项目
- 将 MYWSAT35 文件夹中的所有文件复制到新项目中
- 在 VS 解决方案资源管理器中,选择显示所有文件
如果您现在构建并运行项目,则可以正常运行,没有错误。
5 在 VS 解决方案资源管理器中,对于所有导入的文件,右键单击并选择包含在项目中
现在尝试重建项目我得到错误
The type or namespace name 'GetAdminMasterPage' could not be found
(are you missing a using directive or an assembly reference?)
GetAdminMasterPage.cs 位于WebApplication1\App_Code\class\GetAdminMasterPage.cs,看起来像这样
#region using references
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Caching;
using System.Web.UI;
#endregion
/// <summary>
/// Gets the MasterPage for the user selected Admin Theme.
/// </summary>
public class GetAdminMasterPage : System.Web.UI.Page
{
#region Get Admin MasterPage
protected override void OnPreInit(EventArgs e)
{
if (Cache["cachedAdminMaster"] == null)
{
GetDefaultMasterPage();
}
else
{
string loadMasterFromCache = Cache["cachedAdminMaster"].ToString();
Page.MasterPageFile = loadMasterFromCache;
}
}
private void GetDefaultMasterPage()
{
try
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbMyCMSConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("sp_admin_SelectMasterPage", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.SingleResult);
if (myReader.Read())
{
string masterPageFileName = myReader["ThemeUrl"] as string;
Cache.Insert("cachedAdminMaster", masterPageFileName, null, DateTime.Now.AddSeconds(300), System.Web.Caching.Cache.NoSlidingExpiration);
Page.MasterPageFile = masterPageFileName;
}
myReader.Close();
con.Close();
con.Dispose();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
#endregion
}
现在给出错误的方法之一的示例是
using System;
public partial class admin_admin_edit_css : GetAdminMasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
//gives error The type or namespace name 'GetAdminMasterPage' could not be found
(are you missing a using directive or an assembly reference?)
所以我知道我必须使用 Using xxxxxx; 引用 GetAdminMasterPage,但就是无法找出正确的语法。
首先为什么只有在我选择“包含在项目中”时才会出现错误,而不是在刚刚复制时出现?
其次,如何使用 GetAdminMasterPage 的正确路径修复错误?
【问题讨论】:
-
原始代码是网站“项目”吗?您的空白项目是 Web 应用程序项目吗?
-
是的,我想是的。这是否意味着不可能?
-
这意味着您将苹果和橙子混合在一起,应该会遇到麻烦。我建议将下载的站点下载到本地,右键单击并转换为 Web 应用程序,然后尝试使用该代码。
-
我确实需要将其转换为应用程序,因为我想将其与现有的 Web 应用程序结合起来。如果您将其添加为答案,我会接受。谢谢。
标签: c# asp.net visual-studio namespaces