Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

Is there a way to do this with web.config?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian Simmons - 06 Jun 2007 20:20 GMT
Hi all,

So, I don't have to keep adding the following lines to each of my
code-behind pages:
using System.Data.Sql;
using System.Data.SqlClient;

Is there way in the web.config file to add a setting which will tell each
page to automatically include/use those 2 namespaces?

ASP.NET 2

Thanks,
Brian
Juan T. Llibre - 06 Jun 2007 22:02 GMT
re:
!> Is there way in the web.config file to add a setting which will tell
!> each page to automatically include/use those 2 namespaces?

Yes.

The namespaces element defines a collection of import directives to use during
assembly pre-compilation. This attribute corresponds to the @ Import directive
on an ASP.NET page.

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<pages>
  <namespaces>
    <add namespace ="System.IO" />
    <add namespace="System.Text"/>
  </namespaces>
</pages>
</system.web>
</configuration>

Now, you can use System.IO and System.Text in any page without specifically importing them.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
> Hi all,
>
[quoted text clipped - 9 lines]
> Thanks,
> Brian
John Saunders [MVP] - 06 Jun 2007 23:02 GMT
> re:
> !> Is there way in the web.config file to add a setting which will tell
[quoted text clipped - 7 lines]
> directive
> on an ASP.NET page.

OTOH, you might consider separating your data access from your pages. The
need to reference SQL Server from so many pages may be considered a mild
hint.
Signature

John Saunders [MVP]

Juan T. Llibre - 06 Jun 2007 23:14 GMT
re:
!> OTOH, you might consider separating your data access from your pages. The
!> need to reference SQL Server from so many pages may be considered a mild hint.

Indeed...

Whenever I need to do data access, I compile an assembly which I can reference in any page.
Doing that makes code much more manageable.

;-)

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
>> re:
>> !> Is there way in the web.config file to add a setting which will tell
[quoted text clipped - 4 lines]
>> The namespaces element defines a collection of import directives to use during assembly
>> pre-compilation. This attribute corresponds to the @ Import directive on an ASP.NET page.

> OTOH, you might consider separating your data access from your pages. The need to reference SQL
> Server from so many pages may be considered a mild hint.
Brian Simmons - 07 Jun 2007 14:24 GMT
Yes, John, isn't that the beauty of programming, you have choices in the way
_you_ want to do things.  And neither is "right" or "wrong", it's whatever
works for _you_ and your client.

I asked a simple question, thanks for the answer I was looking Juan.

>> re:
>> !> Is there way in the web.config file to add a setting which will tell
[quoted text clipped - 11 lines]
> need to reference SQL Server from so many pages may be considered a mild
> hint.
Juan T. Llibre - 07 Jun 2007 15:17 GMT
re:
> thanks for the answer I was looking Juan

You're quite welcome, Brian.

As it happened, just last week I had to research that,
so the timing on your question was impeccable.

;-)

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
> Yes, John, isn't that the beauty of programming, you have choices in the way _you_ want to do
> things.  And neither is "right" or "wrong", it's whatever works for _you_ and your client.
>
> I asked a simple question, thanks for the answer I was looking Juan.

>>> re:
>>> !> Is there way in the web.config file to add a setting which will tell
[quoted text clipped - 8 lines]
>> OTOH, you might consider separating your data access from your pages. The need to reference SQL
>> Server from so many pages may be considered a mild hint.
Samuel R. Neff - 07 Jun 2007 18:11 GMT
Yes there are choices, but most certainly there are some wrong
choices.  

Unless you're talking about a one-time-use prototype that you're going
to throw away in a week, I'd agree with John that the db code should
be separate from the aspx code.

Sam

------------------------------------------------------------
We're hiring!  B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC.  Work with a variety of technologies
in a relaxed team environment.  See ads on Dice.com.

>Yes, John, isn't that the beauty of programming, you have choices in the way
>_you_ want to do things.  And neither is "right" or "wrong", it's whatever
[quoted text clipped - 17 lines]
>> need to reference SQL Server from so many pages may be considered a mild
>> hint.
Brian Simmons - 08 Jun 2007 14:41 GMT
> Yes there are choices, but most certainly there are some wrong
> choices.

Your opinion Sam and let's leave it at that.

I asked a simple question, got my answer, and am moving on.

> Yes there are choices, but most certainly there are some wrong
> choices.
[quoted text clipped - 34 lines]
>>> need to reference SQL Server from so many pages may be considered a mild
>>> hint.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.