0

In Visual Studio you can set a default namespace for a VB.NET app using the following screen:

enter image description here

You can do the same for an Visual Studio project that is an ASP.NET web application. It is not available for an ASP.NET website, why? I see this for a website:

enter image description here

4 Answers 4

3

Because of the way ASP.NET Web Sites are distributed and compiled, there is no reason for a default namespace because each ASP.NET file is dynamically compiled and turned into its own DLL the first time the page is loaded (the "old way" of doing ASP.NET).

However, with a Web Application, a bunch of codebehind files (and potentially other code files) are precompiled into a single DLL, which then creates a situation where it is a Good Idea to put all of that into a single namespace.

You can think of it as a Web Site is a collection of Web Pages, but a Web Application is a unified whole.

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

2 Comments

Thanks. You say: "However, with a Web Application, a bunch of codebehind file". Websites have code behind files as well.
Right. With Web Sites, each is dynamically compiled into its own DLL. With Web Applications, a bunch are bundled together in one DLL.
1

Short answer: Web Site projects are missing many features that Web Application Projects have.

See ASP.NET: Web Site or Web Application? for a detailed comparison.

Comments

1

I am using websites and I needed a way to access the BundleConfig, IdentityConfig, and RouteConfig classes and modules from with in my Global.asax file. I was able to put these files into the "App_Code" folder which allows you to put namespaces around the classes and modules.

Here is an example:

Namespace TCEmpSite
    Public Module RouteConfig
        Sub RegisterRoutes(ByVal routes As RouteCollection)
            Dim settings As FriendlyUrlSettings = New FriendlyUrlSettings()
            settings.AutoRedirectMode = RedirectMode.Permanent
            routes.EnableFriendlyUrls(settings)
        End Sub
    End Module
End Namespace

Then in the Global.asax file I was able to do this:

Private Sub Application_Start(sender As Object, e As EventArgs)
        ' Code that runs on application startup
        TCEmpSite.RouteConfig.RegisterRoutes(RouteTable.Routes)
        TCEmpSite.BundleConfig.RegisterBundles(BundleTable.Bundles)
        TCEmpSite.IdentityConfig.ConfigureIdentity()
    End Sub

Hope this helps someone!

Comments

0

Website will not create a dll but web app will create. To create a dll for website,use web_deploy project.

Comments

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.