Error loading class when developing web pages under folders

D

Duron

I created a new folder using VS.NET 2003. Then I created a new web form
under that folder, say, \Member\Default.aspx. However, even if I didn't do
anything to that page, a run-time error appears when I try to run it --

Can not load class MySite._Default.

I am using VB to write codes. Does anyone have any idea why this problem
happens? Thanks!
 
G

Guest

Hi
the error may be b'se of not matching the class name (as in .aspx.vb) does not match with Inheritance in your .aspx page (in <@ Page > directive)
So go to your Default.aspx page and check the "Inherits" attribute in the @ Page directive. The value might be Inherits="<your ASP.NET project name/namespace of this project>.Default" where "Default" is the name of the .aspx file. And also check Default.aspx.vb for class declaration. It should be like "Public class Default"

If they are not same, change and then try again

Hope this will work out fine

K.V.Ravindra Kuma
----- Duron wrote: ----

I created a new folder using VS.NET 2003. Then I created a new web for
under that folder, say, \Member\Default.aspx. However, even if I didn't d
anything to that page, a run-time error appears when I try to run it -

Can not load class MySite._Default

I am using VB to write codes. Does anyone have any idea why this proble
happens? Thanks
 
D

Duron

I've tried several times and different ways in changing the path but still
in vain. Even if I simply create a new folder (/Member) and create a new web
form (Default.aspx) under it, then press F5, the same run-time error occurs.

The Page tag generated by VS.NET is as the following, unmodified,

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Default.aspx.vb" Inherits="MySite._Default" %>

Even worse, if I tried the same thing for 2 or 3 times, the ASP.NET service
gets crashed (it displays a very simple error message like 'Service
Unavailable' in the browser). I need to restart my Windows to make it work
again.

Is this problem reproducible on anyone else' machine? Or I'm the only lucky
one?

An walkaround I'm now taking is make a new project for the folder and it
works fine so far. But I really wonder if this is the best way to develop my
web site.

Ravindra said:
Hi,
the error may be b'se of not matching the class name (as in .aspx.vb) does
not match with Inheritance in your .aspx page (in said:
So go to your Default.aspx page and check the "Inherits" attribute in the
@ Page directive. The value might be Inherits="<your ASP.NET project
name/namespace of this project>.Default" where "Default" is the name of the
..aspx file. And also check Default.aspx.vb for class declaration. It should
be like "Public class Default".
 
J

John Saunders

Duron said:
I created a new folder using VS.NET 2003. Then I created a new web form
under that folder, say, \Member\Default.aspx. However, even if I didn't do
anything to that page, a run-time error appears when I try to run it --

Can not load class MySite._Default.

I am using VB to write codes. Does anyone have any idea why this problem
happens? Thanks!

What happens if you don't use a separate folder? What happens if you use a
file other than default.aspx?
 
G

Guest

Hi Duron,
Actually the concept is : in a single namespace, you can not declare more than one class with same name.
Probably the declaration "Public Class Default" might appears moer than once in your whole application. In your case I hope you have created "Default.aspx" more than once (though it appears in different folders in the same web app).
So the solution can be
1) Change the name of the class in "../Member/Default.asp.vb" file. Say "Public Class MemberDefault".
And accordingly change the @ Page directive as follows:
Inherits = "Mysite.MemberDefault"

2) The other way is decale a separate namespace within the file "./Member/Default.aspx.vb". Say "Namespace Member". Here you no need to change the class declaration or name of the class.
And accordingly change @ Page directive as follows :
Inherits = "Mysite.Member.Default"

Here, one important note is, the name of the .aspx file and its class name may not be the same. It may be diferent.

Hope this will workout,

thanks & regards...
K.V.Ravindra Kumar
 
D

Duron

Hi Ravindra,

I've done some more tests. Here are something I found,

First, if I simply create a new folder, say Member, and then add a new web
page, say Default.aspx, it is working fine, no matter if there is another
Default.aspx at the root.

Then, I copied Web.config into /Member. After this, if I try to run
/Member/Default.aspx, an error message says I have to make this folder an
web application in IIS. I did so. But then the old error (can not load
namespace MySite._Default) occurs.

I haven't done many things to Web.config except the following,

<authentication mode="None">
</authentication>
<authorization>
<allow users="*" />
</authorization>

The reason why I add Web.config to that folder is because I want the root
folder be free to access while /Member needs certification. How do people
normally do this in VS.NET?

Thanks,

-Duron


Ravindra said:
Hi Duron,
Actually the concept is : in a single namespace, you can not declare more than one class with same name.
Probably the declaration "Public Class Default" might appears moer than
once in your whole application. In your case I hope you have created
"Default.aspx" more than once (though it appears in different folders in the
same web app).
So the solution can be
1) Change the name of the class in "../Member/Default.asp.vb" file. Say "Public Class MemberDefault".
And accordingly change the @ Page directive as follows:
Inherits = "Mysite.MemberDefault"

2) The other way is decale a separate namespace within the file
"./Member/Default.aspx.vb". Say "Namespace Member". Here you no need to
change the class declaration or name of the class.
And accordingly change @ Page directive as follows :
Inherits = "Mysite.Member.Default"

Here, one important note is, the name of the .aspx file and its class name
may not be the same. It may be diferent.
 
J

John Saunders

Duron said:
Hi Ravindra,

I've done some more tests. Here are something I found,

First, if I simply create a new folder, say Member, and then add a new web
page, say Default.aspx, it is working fine, no matter if there is another
Default.aspx at the root.

Then, I copied Web.config into /Member. After this, if I try to run
/Member/Default.aspx, an error message says I have to make this folder an
web application in IIS. I did so. But then the old error (can not load
namespace MySite._Default) occurs.

I haven't done many things to Web.config except the following,

<authentication mode="None">
</authentication>
<authorization>
<allow users="*" />
</authorization>

The reason why I add Web.config to that folder is because I want the root
folder be free to access while /Member needs certification. How do people
normally do this in VS.NET?

People normally use <location> tags.
 
J

John

I could be wrong (ultranewb, here), but I believe the reason you're getting
an error message that says you have to 'make the folder an application' in
IIS is because you're trying to specify authentication again in your second
web.config file. Authentication can only be set in the web.config file in
the root directory, as it pertains to the whole application. So just remove
the <authentication> tag pair from the config file in the subdirectory and
everything else should be fine - the authorization section does the work you
need. Or you can, as was suggested, use 'location' tags in a single
web.config file at root.

HTH

-John
 
D

Duron

Hi John,

In my design, the root folder of my site is open for everyone (don't need to
login) while the sub-folders (say /Member) need authentication. When I was
not using VS.NET (I used notepad to write codes) there is a Web.config in
the root folder and another in /Member, there was no problem at all.
 
J

John

Hey there -

Yeah, that should be fine; I think the problem only occurs when you try
to specify 'authentication' in any web.config file besides the one that's at
the root directory. So you can specify different authorizations in both, but
authentication only in one. The authentication you specify in the web.config
file at root directory then applies to the entire project, even if your root
directory authorizes everyone (and your subs have access limitations).

It's highly likely I'm misunderstanding the issue, though. ;) Heheh...
Good luck!

-John
 
D

Duron

I've created another project for the sub folder and it's working fine (so
far). But still thanks for your help.

- Duron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top