Appcode and AppData not working in Asp.net - c#

I have created empty web Application on .net (Not Website).So I add Admin folder and under this i have added two folders , APPCode and AppData. When I am giving reference of AppData in Appcode it is not working.
I have class test.cs in AppCode and DAL.cs in AppData and i want to access DAL class in test. Here what I am using
System MyProject.Admin.AppData , One thing is that after Syatem .net not showing any inyellisence and all the above i coded myself.plz help me what to do.

In Visual Studio - if you right click a file in App_Code and select properties, you need to select Build Action and set it to Compile. That will activate the intellisense for those classes.
This happens to me a lot...

Related

Why can't I call classes in the App_Code folder?

My web application project has an App_Code folder. I want to use the methods in these classes from my aspx.cs pages.
There are some classes in the App_Code folder I can access, and some I can't.
I can't spot any differences between them. For instance, all classes have the Build Action property set to Compile.
Is there anything else I should be doing to ensure I can call the classes in the App_Code folder?
With Web Application Projects, you shouldn't be adding App_Code folder. It is intended for Website Projects. With Web Application projects, all your class files are anyways compiled.
The same result can be achieved by creating any folder (MyCodeFiles) and having all the class files inside it. That is why there is no option to create an App_Code option in the VS menu.
If it works, can you try adding a custom folder and see if it has any issues?
If you still need the App_Code to be there, then try checking the namespaces of the files & the build action again.

The type 'typename' exists in both App_Code.dll and solution.dll

I have a Visual Studio 2012 solution which includes a Web Application Project plus a number of Class Library Projects. The solution builds successfully in VS but when I browse to an ASPX page I get this error:
Compilation Error
S0433: The type '<type-name>' exists in both
'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\root\3e98edf3\c4c22795\App_Code.dll' and
'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\root\3e98edf3\c4c22795\assembly\dl3\ef67a753\a19c0f5f_801ecf01\
my-solution.DLL
My Web Application project does not contain an App_Code folder, only an AppCode (note the missing underscore) folder. I inherited this project from another developer so can't find out why it is setup this way.
I have tried clearing my temporary ASP.net files and have Cleaned and Rebuilt the solution.
Found the problem! When viewing through Windows Explorer, I had an AppCode and an App_Code folder with the same files in each. I guess whoever worked on this before me had created AppCode and somewhere along the way the new App_Code was added.
This is what caused the duplicate type name, one compiled into App_Code.dll and the other into solution.dll

App_Code and server

I'm having a "tiny" issue with my App_Code folders.
I'm learning ASP.NET and, therefore, ordered a webserver with the support of ASP.NET 4.0. I'm using Visual Web Developer to program my webpages. When I upload my website to this webserver everything runs fine.
However, if I then add another web project to my server, my App_Code folder gets all messy. The server wants all my class files in the App_Code folder in the root. Is there any way I can create subdirectories in my App_Code folder or something to keep my projects organized or am I missing the point here?
You should take a look at codeSubDirectories in the web.config
Alright I found a solution to my problem. Although most of your answers might work aswell, this proved to be the best in my case. I created a subdomain and threw all files into that folder and it worked fine.
You should try to avoid using the App_Code folder for your own stuff, especially if you're using a web application project.
Whenever you convert a website to a web application project, the process actually renames your existing App_Code directory to Old_App_Code.
See Here, even though this is specific to converting .net 2.0 apps, I believe it still holds true in 4.0 since converting a 4.0 app does the same thing.:
VERY, VERY IMPORTANT: Because ASP.NET 2.0 tries to dynamically compile any classes it finds under the /App_Code directory of an application at runtime, you explictly DO NOT want to store classes that you compile as part of your VS 2005 Web Application Project under an "app_code" folder. If you do this, then the class will get compiled twice -- once as part of the VS 2005 Web Application Project assembly, and then again at runtime by ASP.NET. The result will most likely be a "could not load type" runtime exception -- caused because you have duplicate type names in your application. Instead, you should store your class files in any other directory of your project other than one named "app_code". This will be handled automatically by the "Convert to Web Applicaiton" command. This command will rename the folder Old_App_Code.
If you have access to a hosting control panel it's probably best to configure your hosting environment with a virtual folder for your second website and run it from the sub folder, e.g. www.example.com/project-b. The first site can still be running in the root folder, e.g. www.example.com.
So both sites will essentially be isolated from each other (just like they are now isolated as two separate projects in Visual Web Developer Express). And both sites have their own App_Code folder (and web.config file).
If you don't have access to a configuration panel, most hosting providers are willing to add a virtual folder for you, since it's really not a special requirement.
The virtual folder should show up as a regular folder in your FTP folder, usually inside the www or wwwroot folder. Now you can copy your project files into that folder.
Take care to use root-relative paths for URLs in your second project, so all links will work even when the website is run from the subfolder. Root-relative URLs look like this:
<asp:HyperLink runat="server" NavigateUrl="~/Default.aspx" />
<asp:Image runat="server" NavigateUrl="~/images/logo.png" />
This will automatically go to www.example.com/project-b/Default.aspx and www.example.com/project-b/images/logo.png when the website is deployed in the virtual folder.
If you need to re-use code from one site in the other, it's typically best to move such code into a separate Class Library project type, and then add a reference to that project to each website project (right-click the website project, choose Add reference..., then select the Projects tab and select the Class Library project).

AppData folder under the virtual directory?

I created a web application in asp.net with sql server 2008 .I made a web setup project.Deployed into the server(IIS) with the msi i created.So for some reason a folder named "appdata" is getting created where the the application is deployed.
I even deleted the folder in my code and built again the msi.But still the folder is getting created.
Earlier i used the aspnet.mdf to create users but i am no longer using it as i am using a sql table.But still i am unable to know where my fault is .. Does it have some thing to do with my web.config file ?
Check to make sure that the App_Data folder isn't excluded from your project. If it is excluded, delete it from the project entirely and republish.
If that doesn't work:
Under the Publish dialog, make sure that the "Include files from the App_Data folder" checkbox is unchecked.

Custom Namespace on .NET web app

So I wrote some custom classes and put them all in a namespace, call it "Sphere".
On my aspx.cs codebehind file, I have "using Sphere;" written. I know that this works because it's always worked until I copied this project to a new folder. Also, even when I click "view in web browser" everything works perfectly.
Simply, Visual Studio 08 is not recognizing the namespace and so I cannot build without an error and consequently cannot debug. Thanks for the help!
edit:
I have my namespace in my App_Code folder in a .cs file
Are your custom classes in a separate project? If so, you might need to add a reference to that project. If you have copied the project to a new folder, the path to your Sphere DLL/project in VS2008 might be broken.
I actually just figured it out:
My .cs files were set to "build action: content" rather than "compile." I right-clicked + properties all my files and changed the build action, and now it all works!
Sounds like missing reference.
In your new project, do you have a reference to the project that defines the actual Sphere namespace?
Check your references. It's possible VS is no longer finding them after you moved your application's folder.
It sounds like when you moved the files the references were broken. If the sphere classes are in a seperate dll try deleting and re-adding the reference. If it is just in a .de file be sure that filein the project is still in the relative path.
Probably you got this error:
The type or namespace name 'CustomClass' could not be found (are you missing a using directive or an assembly reference?)
And the reason the type was not in the assembly is that App_Code folder is specific folder for Web Site Projects. These files get compiled at runtime when they are deployed on server and not when you are building the project.
In Web Application Project every file has Build Action property. By default the classes files have value of Compile. But if the class is created in App_Code file it gets value Content. and does not get compiled when running as Application.
A the end the App_Code folder is not meant to be used in Web Application. Or as you figured it out you can manually change the Build Action to Compile.
I found the answer by searching these links:
Vishal Joshi's Tangent - App_Code folder doesn’t work with Web Application Projects (WAPs)
Build Action" property set to "Content" for class files inside App_Code folder

Categories

Resources