所以我在我正在设计的新网站上的App_Code文件夹中遇到了一个非常奇怪的问题.
我在App_Code文件夹中的命名空间内有一个基本类.当我设置命名空间并从类中创建一个对象时,IDE中的一切工作正常.它会显示有关悬停的类摘要,当您单击"转到deffinition"时,它将转到类文件.它也适用于localy.
但是,当我将网站加载到我的服务器上时,我在访问该页面时收到此错误消息:
第10行:使用System.Web.UI.WebControls;
第11行:使用System.Web.UI.WebControls.WebParts;
第12行:使用xxxx.xxxx
编译器错误消息: CS0246 :找不到类型或命名空间名称'xxxxxx'(您是否缺少using指令或程序集引用?)
我知道类文件存在的事实.任何人都知道最新情况怎么样?
编辑:
约翰,是的,这是一个2.0网站.
拥有App_code&App_data文件夹有什么意义?
为什么我的objectDataSource不检测类,除非文件在App_Code中?
请提供尽可能详细的信息,我是ASP.Net的新手
我在"App_Code"文件夹中的文件中有一个类.我可以在"aspx"文件中使用它,但不能从代码隐藏文件中使用它.如何让代码隐藏可见?
注意:这是Mono上的ASP.Net,我直接编写类,而不是使用IDE来编译它们
我的文件:
<%@ Page language="c#" src="TestAppCode.aspx.cs" Inherits="TestAppCode.TestAppCode" AutoEventWireup="true" %>
<html>
<head>
<title>Test App_Code Folder</title>
</head>
<body>
<form id="contactForm" runat="server">
<asp:TextBox id="Name" runat="server" ></asp:TextBox>
<asp:TextBox id="Age" runat="server" ></asp:TextBox>
<asp:Button ID="Submit" runat="server" Text="Submit" onclick="SubmitForm" />
</form>
</body>
<html>
Run Code Online (Sandbox Code Playgroud)
using System;
using System.Web.UI.WebControls;
namespace TestAppCode
{
public class TestAppCode : System.Web.UI.Page
{
protected void SubmitForm(object sender, EventArgs e)
{
//It fails here with the error: CS0246: The type or namespace name
//`MyAppCodeClass' could not be found. Are you missing …Run Code Online (Sandbox Code Playgroud) 标题中说明的问题很简单:有没有办法在'App_Code'之外使用剃刀助手?
示例(HtmlEx.cshtml文件):
@helper Script(string fileName, UrlHelper url)
{
<script src="@url.Content("~/Scripts/" + fileName)" type="text/javascript"></script>
}
Run Code Online (Sandbox Code Playgroud)
我问这个是因为我在App_Code中没有任何其他内容; 我想构建我的项目有点不同.
谢谢.
更新:我不想要任何其他类型的扩展.斯科特在这里谈到的只是纯粹的剃刀助手:http://weblogs.asp.net/scottgu/archive/2011/05/12/asp-net-mvc-3-and-the-helper-syntax -within-razor.aspx
我在App_Code中创建了一个新类
namespace Site {
public class MyClass {
public MyClass() {
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的Global.asax.cs
namespace Site {
public class Global : System.Web.HttpApplication {
protected void Application_Start(object sender, EventArgs e) {
*MyClass myClass = new MyClass();*
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误发生在:MyClass myClass = new MyClass();
找不到类型或命名空间名称'MyClass'(您是否缺少using指令或程序集引用?)
我在这里错过了什么?
所以我有一个ASP.NET网站(不是Web应用程序),我在VS2010中用C#制作.它在我的机器上运行正常,但是当我将它上传到它托管的站点时,它将无法编译,给出:"CS0246:找不到类型或命名空间名称'DataAccess'(你是否缺少using指令或装配参考?)"
我一直在使用VS中的复制网站功能,并且在我想将自己的类放在App_Code文件夹中并使用它之前没有任何问题.我在其他答案中读到了将.cs属性更改为"编译"而不是"内容",但在文件属性中没有这样的选项...只有文件名,完整路径和自定义工具.这是.cs文件中的代码:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
/// <summary>
/// Provides access to SQL Server database.
/// </summary>
///
public class DataAccess
{
//Variables & public properties ***********************************
private string connectionString = "";
private int recordCount = -1;
/// <summary>
/// Property: gets count of records retrieved or changed
/// </summary>
public int Count
{
get
{
return recordCount;
}
}
//Class constructor is executed when object is initialized ***********
/// <summary>
/// Connection string name in …Run Code Online (Sandbox Code Playgroud) The base class includes the field 'lbl', but its type (web.App_Code.CustomLabelControl) is not compatible with the type of control (web.App_Code.CustomLabelControl).
我以同样的方式做了很多自定义控件,但地狱这个错误让我疯了.我有一个Web应用程序项目,App_Code目录中的下面的类是web.config中的tagprefix引用,用于类中的控件.现在我该怎么做?
<system.web>
<pages>
<controls>
<add namespace="web.App_Code" tagPrefix="CControls"/>...
Run Code Online (Sandbox Code Playgroud)
<form id="form1" runat="server">
<div>
<CControls:CustomLabelControl runat="server" OnClickText="Welcome" ID="lbl">
</CControls:CustomLabelControl>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
namespace web.App_Code
{
public class CustomLabelControl : Control, IPostBackEventHandler, IPostBackDataHandler
{
private string _onClickText;
public CustomLabelControl()
{
}
public string OnClickText
{
get { return _onClickText; }
set { _onClickText = value; }
}
public void …Run Code Online (Sandbox Code Playgroud) 将应用程序代码(App_Code)划分为单独文件的一般准则/陷阱应该是什么?
我发现,随着时间的推移,原始文件与命名空间层次结构的演变方式不匹配.如何随着时间的推移直观地组织应用程序代码容器?
档案部门的目标应该是什么?代码可移植性?关注点分离?一般功能背景?变化的频率?他们应该努力与班级建立1-1关系吗?
将代码拆分为多个较小的文件与合并为少量文件有什么影响?
我经常想到这一点,但从未真正达成适用于所有情况的任何一般性结论.
我已经安装了CocoaPods的最新版本的RxSwift.
虽然尝试使用RxSwift的简单元素,NotificationsCenter.default.rx但它不会提示使用方法.有趣的是,有时它会提示其他pod,有时候不会提示其余的,所以我必须打开XCode来检查代码更正.
我该如何解决这个问题?
我正在开发一个asp.net网络应用程序,我的app_code中有几个类,但由于某种原因,我不能在我的代码中使用它们中的任何一个.我尝试使用相同的命名空间,我尝试在两个文件中没有任何命名空间,但没有任何帮助.
这是我的页面代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LinkedIn;
using LinkedIn.ServiceEntities;
namespace Authentication
{
public partial class LinkedinMoreInfo : LinkedinBasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在课堂上的代码:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using LinkedIn;
namespace Authorisation
{
public class LinkedInBasePage : System.Web.UI.Page
{
private string AccessToken
{
get { return (string)Session["AccessToken"]; }
set …Run Code Online (Sandbox Code Playgroud) app-code ×10
asp.net ×8
c# ×4
.net ×1
app-data ×1
appcode ×1
code-behind ×1
global-asax ×1
helper ×1
ios ×1
mono ×1
postback ×1
razor ×1
swift ×1
web-controls ×1