我遇到了很多问题,我在使用NotePad ++时出于一些不明原因在Vb.Net Asp.net中进行编码,在我的服务器上我有一个文件夹,我想添加一些.vb类然后在aspx中文件,只需导入命名空间并创建这些类的实例......应该很简单,不是吗?
嗯,这是我的架构:
我有一个文件名default.aspx,其中包含:
<%@ Import Namespace="Geo" %>
<%
Dim a As Access = New Access()
Response.Write(a.hasAccess())
%>
和名为aspxcomponents
的子文件夹中的类名Access以下是课程访问内容:
Namespace Geo
Public Class Access
Function hasAccess() As Boolean
Return True
End Function
End Class
End Namespace
好吧,当我执行default.aspx时,我收到以下错误:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30002: Type 'Access' is not defined.
Source Error:
Line 1: <%@ Import Namespace="Geo" %>
Line 2: <%
Line 3: Dim a As Access = New Access()
Line 4: Response.Write(a.hasAccess())
Line 5: %>
Source File: C:\...\default.aspx Line: 3
Show Detailed Compiler Output:
C:\Windows\SysWOW64\inetsrv> "C:\Windows\Microsoft.NET\Framework\v2.0.50727\vbc.exe" /t:library /utf8output /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\17edf889\308e2904_d4a7cd01\obout_SuperForm.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\90a90acc\06f1d546_d4a7cd01\obout_ListBox.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\16815892\0259b030_d4a7cd01\AjaxControlToolkit.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\db59a808\e25edd3b_d4a7cd01\obout_Flyout2_NET.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\1b343ee7\26831f32_d4a7cd01\obout_AJAXPage.DLL" /R:"C:\Windows\assembly\GAC_MSIL\System.WorkflowServices\3.5.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.IdentityModel\3.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\04af17f9\ca3b7804_d4a7cd01\obout_Tree_DB_Net.DLL" /R:"C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\2f6922c7\ba568500_d4a7cd01\obout_Show_Net.DLL" /R:"C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\Windows\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\67fcad05\b8cabd41_d4a7cd01\obout_ImageZoom_NET.DLL" /R:"C:\Windows\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\e0bf0dd3\2ae92003_d4a7cd01\obout_Splitter2_Net.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\923ae5b1\e6b6b705_d4a7cd01\obout_Window_NET.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\284fee82\00968846_25e3c701\obout_ASPTreeView_2_NET.DLL" /R:"C:\Windows\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\d8821591\e82de323_ab03ce01\Server.DLL" /R:"C:\Windows\assembly\GAC_MSIL\System.ServiceModel.Web\3.5.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\3047a6af\a0af073a_d4a7cd01\obout_ComboBox.DLL" /R:"C:\Windows\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\766a113f\729f1038_d4a7cd01\obout_Calendar2_Net.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\49cf6573\9c28c516_d4a7cd01\Microsoft.Vbe.Interop.DLL" /R:"C:\Windows\assembly\GAC_MSIL\System.Runtime.Serialization\3.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\3e1c6afb\ac61a245_d4a7cd01\obout_Interface.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\419549c8\ce7cf703_d4a7cd01\obout_TextMenu.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\4e2fd5b6\be9cf743_d4a7cd01\obout_Grid_NET.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\7c45df4e\1c65fb14_d4a7cd01\Microsoft.Office.Interop.Word.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\161a8730\ea77face_d5a7cd01\obout_FileUpload.DLL" /R:"C:\Windows\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\b94efe06\e8d6b43b_d4a7cd01\obout_EasyMenu_Pro.DLL" /R:"C:\Windows\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\526f4d83\f431a930_d4a7cd01\Obout.Ajax.UI.DLL" /R:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\assembly\dl3\7043b70c\48142501_d4a7cd01\obout_SlideMenu3_Pro_NET.DLL" /out:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\App_Web_9j7lk7lp.dll" /D:DEBUG=1 /debug+ /define:_MYTYPE=\"Web\" /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Specialized,System.Configuration,System.Text,System.Text.RegularExpressions,System.Web,System.Web.Caching,System.Web.SessionState,System.Web.Security,System.Web.Profile,System.Web.UI,System.Web.UI.WebControls,System.Web.UI.WebControls.WebParts,System.Web.UI.HtmlControls "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\App_Web_9j7lk7lp.0.vb" "C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\App_Web_9j7lk7lp.1.vb"
Microsoft (R) Visual Basic Compiler version 8.0.50727.5420
for Microsoft (R) .NET Framework version 2.0.50727.5472
Copyright (c) Microsoft Corporation. All rights reserved.
C:\...\default.aspx(3) : error BC30002: Type 'Access' is not defined.
Dim a As Access = New Access()
~~~~~~
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\84e1764c\a7c5af94\App_Web_9j7lk7lp.0.vb(15) : warning BC40056: Namespace or type specified in the Imports 'Geo' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
Imports Geo
~~~~~~~~~~~~~~~
ANY!帮助将是伟大的!赞赏...我非常绝望:S
我尝试的一切都不起作用 - .-
谢谢
我做了一些测试,看起来即使文件Access.vb无效(用namejdacosijdfspace替换名称空间)我没有收到任何错误..
... 说真的,有人吗?我真的很绝望:S
答案 0 :(得分:2)
两个问题。
首先,该类是公共的,但该函数未经修改。这意味着该功能是私有的(或者可能受保护/朋友,具体取决于上下文)。你需要这个:
Namespace Geo
Public Class Access
Public Function hasAccess() As Boolean
Return True
End Function
End Class
End Namespace
其次,您导入了命名空间,但没有告诉框架该命名空间的代码所在的框架。尝试将.vb文件放在特殊App_Code folder中。或者,您可以将文件构建为* .dll作为类库的一部分,然后将其放在特殊的/ bin文件夹中。
答案 1 :(得分:0)
您需要将导入语句更改为Imports。
正确的语法是:
Imports Geo
作为替代方法,您可以删除Import语句并完全限定Access类:
Dim a As Geo.Access = New Geo.Access()