1

I wonder how to use namespaces in asp.net c# project? I am prepend in classes defined in AppCode

namespace MyNamespace
{
    class code My Class
    {
    }
}

If i do so then I see that in a view where I use this class must include this namespace(of course). Can't I include this in webconfig to include it all over? Update:

The reason I want to use namespaces is because I want to create a dll file of files from AppCode so application will run quicker. Even though I see that no dll is built when I build the site.

0

2 Answers 2

1

If you are using a Web Application and have a Class or ClassLibrary and want to call this class in your code behind ".asc" .

You can Add Reference in the WebApplication, so you choose the Class in Project tab. Then u can call : using Class.namespace ...

Sign up to request clarification or add additional context in comments.

Comments

1

First of all if you are planning to use WebSite project change it to Web Application Project, web site project is mostly deprecated and just allows you less functionality in project configurating (surely their is some in advantages like "copy site" but i don't think they are very usefull).

So in this type of project you don't need to use App_Code and surely it's easy to add namespace to web.config:

4 Comments

Can I open that in WebMatrix, because those are just web projects.
Not sure, haven't got experience with it
I wrote this in webconfig> <system.web> <httpRuntime requestValidationMode="2.0" /> <pages enableViewStateMac="false"> <namespaces> <add namespace="MyNamespace" /> </namespaces> </pages> and despite this if I want to use a class from this namespace in a view I have to include namespace too
@AlexaAdrian, You can just ignore the compiler errors, because when you run the application it will work. However it is best to close the solution and reload it. This way, your intellisense will be working and you won't get any compiler errors anymore. Let me know if it works for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.