CS0103: The name does not exist in the current context dev to webserver issue - asp.net

I have created a few classes that operate separately from the normal aspx.cs files. When I added a new class I was prompted to add these to app_data, i did. So I copied out these files and the app_data folder and it cannot be found. I tried the .cs files at the root of the website and they still could not be found.
I'm sure i'm messing up on a common mistake.
Thanks!

They need to be in the App_Code folder.

Related

Resource not exist in current context in razor view

I have Resources.resx file created in my webapp wwwroot/Resources folder.
When i try to use it in razor view as #Resources.SomeValue i got an error
The name 'Resources' does not exist in the current context
When i move file to wwwroot folder, i can use resource.
I have tried to use #Resources/Resources.SomeValue, but i got same error
Is there a way to move this file somewhere away from root folder?
In the web.config file in your Views folder, add a namespace to the namespaces node for your Resource folder. Should look something like this:
<add namespace="wwwroot.Resources" />
This should allow you access to that folder in your views. You may have to close and reopen the view to get Intellisense.

ASP.NET App_Code in folder

I am working on a ASP.NET VB project. The host is pretty restrictive, so the App_Code folder has to be placed under the wwwroot folder.
My current folder structure (on the server) looks like this:
root
<-- Cant create folders or files here, host is restrictive.
wwwroot
App_Code
Class.VB
Styles
style.css
default.aspx
web.config
It seems to be working, if Class.vb contains errors, i get a compilation error on the website, so i know its compiling the class.
But i am unable to use the class in my other code files.
Example:
Dim emailFilter As Validation = New Validation()
I get this error in VS2010:
Type 'Validation' is not defined
How do i use the App_Code folder when its inside another folder?
Could it be an issue with namespaces? I might be more inclined to create a library for your validation class and add a reference to it instead.
I did find some similar issues to yours and they all referenced setting the Build Action for the class to 'compile'.
Classes residing in App_Code is not accessible

Page class outside of App_Code will not compile

I have a website that has 2 files as follows:
page.aspx
page.aspx.cs
It used to be that I could just drop new files onto the web server and IIS would automatically compile the files and I could access the page e.g.
http://www.website.com/page.aspx
... and the associated functionality in the page class contained in the .cs file would work nicely.
Now I get the error: "Could not load type namespace.classname" which refers to my page class.
Now for some strange reason I have to put all my .cs files, even page classes into the app_code folder.
All that has changed on my website is that I reorganised the structure so that instead of my pages being on the web root they are now inside http://.../newfolder/page.aspx.
For some reason all my page.aspx.cs files now have to be in app_code.
Any ideas?
Sounds like you are mixing up a Web Application Project and a Web Site.
Are you sure the files are exactly the same? Perhaps one #Page directive says CodeBehind=Page.aspx.cs and the other says CodeFile=Page.aspx.cs?
CodeBehind requires project compilation, so you cannot just drop in a new .cs file, you need to upload a new compiled DLL. CodeFile will allow dynamic compilation.
The App_Code directory is dynamically compiled (in both cases) when your app is accessed, so the Inherit directive has a valid type when you put the file there. In general, don't do this. You want the .cs file to go with the .aspx file. Use App_Code for business logic or utility classes that aren't associated with a particular page.
Finally, is this new subdirectory set up as a new app in IIS? What does the web.config file in your new directory change? Are you running the same version of ASP.NET? Check the "compilation" tag. I'm not sure what you could do there to cause this, but I'm sure you could cause some chaos.

Not able to create an instance of a class

In a Project I have different modules or folders.In a module I have a namespace called idsobject.I have class in this namespace.
In another CS fle in the same folder I'm trying to access this class.But i'm not able.while if put that cs file in aPP_code than i able to get that class.
how to access the class in another cs file within the same folder.
thanks in advance
In an ASP.NET web site project, *.cs files are only compiled and made available to the rest of the application if they're located in the App_Code folder, or a subfolder in App_Code, or if they are associated with a *.aspx as code behind. The architecture is intended to allow full server-side compilation. You can't just put a *.cs anywhere and expect IIS to be able to find it, compile it, and link it with the rest of the app.
With an ASP.NET web application, you can put *.cs files where ever you want, because they are compiled by Visual Studio using details that are kept in the project file.
I'm guessing that you're using a web site project, which is why it works when you put the file in App_Code.
First check the namespace. If you accessing the correct namespace then perhaps the class access is set to private.
You could give us some extra information.
This sounds strange. Putting a class in a file in a Web project with a .cs extension should work just fine no matter which folder the file is located.
The only thing I can suggest is to make sure that there is at least a
using idsobject;
line at the top of the code unit where you are trying to access the class. The default behaviour for ASP.NET Web forms is for no namespace to be defined, which can sometimes lead to confusion.
The class should be marked as public if you've tried to access it from another namespace.
If it doesn't help, please post here a problematic code snippet.

Compile asp.net web site and certain references are not being copied to Temporary ASP.NET Files Folder

Scenerio: I have an asp.net website that I am compiling successfully but keep getting an error in the browser saying that it can not find a referenced dll in the solution. I checked the directory in the Temporary ASP.NET File location and all of my referenced dll's are there except for the one it is failing to retrieve. I manually added the location it was looking for and the site worked.
The dll is referenced in code so it should have been moved to the temp folder. Does anyone have any idea why this would happen? I checked the properties on the referenced dll and copy local is set to true so it should be moved to the output directory.
Right click on the DLLs in your References/Bin directory in your project and look at the Copy Local property. Make sure they are set to True.
After hours of searching google and finding nothing, I decided to take a look at the actual properties of the dll file. To my surprise the issue ended up being permissions. For some reason the one dll that was beating me up all day needed correct permissions to be moved to the output folder. ughhh.
When you say "referenced in code" do you mean it's listed in the project file's Reference section? Or do you mean you are manually referring/naming it in your source code?
Have you tried this in your web.config (or higher up the config chain?)
<hostingEnvironment shadowCopyBinAssemblies="false" />
Where exactly are you expecting it to be copied? What is the path the error message is reporting?

Resources