473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how do I access the application object within another assembly?

Hello All. I have an asp.net application with 3 different assemblies. They
are like this:

1) Assembly: PublicSite (This contains the website UI)
Root namespace: PublicSite

2) Assembly: PublicSite.MyProfile.Business (This contains the business
rules)
Root namespace: PublicSite

3) Assembly: PublicSite.MyProfile.Data (This contains the data layer)
Root namespace: PublicSite

I also have my connection strings defined in the application object. So, in
the main assembly, I can access the connection strings by using
current.application("myConnection"). However, I need to access the
Application object in my Business assembly. How can I do that???

I tried to do this: Dim x as new System.Web.httpContext.Current, but that
didn't work. When I use intellisense, I get the following after System.Web:
{AspNetHostingPermision}, {AspNetHostingPermissionAttribute} and
{AspNetHostingPermissionLevel}

I believe that it's easy to make an argument to say that one should never
try to access the asp.net application object from within a business class,
but currently, we only use these objects for asp.net and not windows
applications. (not that I'm making excuses.....)

Thank you very much for your help!

SteveS
ss*****@trendmls.com
Nov 18 '05 #1
6 2225
You should be able to use HttpContext.Current without
problems. Make sure you are not declaring this in your
class member declaration, but in your method.

Tu-Thach
-----Original Message-----
Hello All. I have an asp.net application with 3 different assemblies. Theyare like this:

1) Assembly: PublicSite (This contains the website UI)
Root namespace: PublicSite

2) Assembly: PublicSite.MyProfile.Business (This contains the businessrules)
Root namespace: PublicSite

3) Assembly: PublicSite.MyProfile.Data (This contains the data layer) Root namespace: PublicSite

I also have my connection strings defined in the application object. So, inthe main assembly, I can access the connection strings by usingcurrent.application("myConnection"). However, I need to access theApplication object in my Business assembly. How can I do that???
I tried to do this: Dim x as new System.Web.httpContext.Current, but thatdidn't work. When I use intellisense, I get the following after System.Web:{AspNetHostingPermision}, {AspNetHostingPermissionAttribute} and{AspNetHostingPermissionLevel}

I believe that it's easy to make an argument to say that one should nevertry to access the asp.net application object from within a business class,but currently, we only use these objects for asp.net and not windowsapplications. (not that I'm making excuses.....)

Thank you very much for your help!

SteveS
ss*****@trendmls.com
.

Nov 18 '05 #2
That didn't work. I get the error "HttpContext is not declared" when I
try this:
Dim x as string = HttpContext.Current.Application("xxx").tostring .
..or..
Dim x as string = System.Web.HttpContext.Current.Application("xxx"). Tostring

Here is my function:

Public Shared Function GetOpenConnection(ByVal WhichServer as ServerType) as
SqlConnection
Dim conn as new SqlConnection
Select Case WhichServer
Case ServerType.TestServer
conn.ConnectionString =
HttpContext.Current.Application("MyConnectionStrin g")
End Select
... more code...
End Function

Any ideas???

Thanks!
"Tu-Thach" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...
You should be able to use HttpContext.Current without
problems. Make sure you are not declaring this in your
class member declaration, but in your method.

Tu-Thach
-----Original Message-----
Hello All. I have an asp.net application with 3

different assemblies. They
are like this:

1) Assembly: PublicSite (This contains the website UI)
Root namespace: PublicSite

2) Assembly: PublicSite.MyProfile.Business (This

contains the business
rules)
Root namespace: PublicSite

3) Assembly: PublicSite.MyProfile.Data (This contains

the data layer)
Root namespace: PublicSite

I also have my connection strings defined in the

application object. So, in
the main assembly, I can access the connection strings by

using
current.application("myConnection"). However, I need

to access the
Application object in my Business assembly. How can I

do that???

I tried to do this: Dim x as new

System.Web.httpContext.Current, but that
didn't work. When I use intellisense, I get the

following after System.Web:
{AspNetHostingPermision},

{AspNetHostingPermissionAttribute} and
{AspNetHostingPermissionLevel}

I believe that it's easy to make an argument to say that

one should never
try to access the asp.net application object from within

a business class,
but currently, we only use these objects for asp.net and

not windows
applications. (not that I'm making excuses.....)

Thank you very much for your help!

SteveS
ss*****@trendmls.com
.

Nov 18 '05 #3
Did you import the namespace into your library? Did you
reference the System.Web.dll for your project?

Tu-Thach
-----Original Message-----
That didn't work. I get the error "HttpContext is not declared" when Itry this:
Dim x as string = HttpContext.Current.Application ("xxx").tostring ...or..
Dim x as string = System.Web.HttpContext.Current.Application("xxx"). Tostring
Here is my function:

Public Shared Function GetOpenConnection(ByVal WhichServer as ServerType) asSqlConnection
Dim conn as new SqlConnection
Select Case WhichServer
Case ServerType.TestServer
conn.ConnectionString =
HttpContext.Current.Application("MyConnectionStri ng")
End Select
... more code...
End Function

Any ideas???

Thanks!
"Tu-Thach" <an*******@discussions.microsoft.com> wrote in messagenews:07****************************@phx.gbl...
You should be able to use HttpContext.Current without
problems. Make sure you are not declaring this in your
class member declaration, but in your method.

Tu-Thach
>-----Original Message-----
>Hello All. I have an asp.net application with 3

different assemblies. They
>are like this:
>
>1) Assembly: PublicSite (This contains the website UI) > Root namespace: PublicSite
>
>2) Assembly: PublicSite.MyProfile.Business (This

contains the business
>rules)
> Root namespace: PublicSite
>
>3) Assembly: PublicSite.MyProfile.Data (This contains

the data layer)
> Root namespace: PublicSite
>
>I also have my connection strings defined in the

application object. So, in
>the main assembly, I can access the connection strings
by using
>current.application("myConnection"). However, I need

to access the
>Application object in my Business assembly. How can I

do that???
>
>I tried to do this: Dim x as new

System.Web.httpContext.Current, but that
>didn't work. When I use intellisense, I get the

following after System.Web:
>{AspNetHostingPermision},

{AspNetHostingPermissionAttribute} and
>{AspNetHostingPermissionLevel}
>
>I believe that it's easy to make an argument to say
that one should never
>try to access the asp.net application object from
within a business class,
>but currently, we only use these objects for asp.net
and not windows
>applications. (not that I'm making excuses.....)
>
>Thank you very much for your help!
>
>SteveS
>ss*****@trendmls.com
>
>
>.
>

.

Nov 18 '05 #4
Steve,

Even i am having a similar issue...
writing a custom assembly which does serialization and lot of other junk...
want to check whether user is authorised to use the page
that assembly will be reference from within a class in ASP.NET app.

I tried to put a reference for System.Web;
not helpful... doesnt let me get the context...
looked a bit further and read something bout IHttpModule and IHttpHandler..
saying need to implement them in order get access to current context..

woud appreciate some help from someone who's done it before...

--
Regards,

HD

"SteveS" <ss*****@trendmls.com> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
That didn't work. I get the error "HttpContext is not declared" when I
try this:
Dim x as string = HttpContext.Current.Application("xxx").tostring .
.or..
Dim x as string = System.Web.HttpContext.Current.Application("xxx"). Tostring
Here is my function:

Public Shared Function GetOpenConnection(ByVal WhichServer as ServerType) as SqlConnection
Dim conn as new SqlConnection
Select Case WhichServer
Case ServerType.TestServer
conn.ConnectionString =
HttpContext.Current.Application("MyConnectionStrin g")
End Select
... more code...
End Function

Any ideas???

Thanks!
"Tu-Thach" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...
You should be able to use HttpContext.Current without
problems. Make sure you are not declaring this in your
class member declaration, but in your method.

Tu-Thach
-----Original Message-----
Hello All. I have an asp.net application with 3

different assemblies. They
are like this:

1) Assembly: PublicSite (This contains the website UI)
Root namespace: PublicSite

2) Assembly: PublicSite.MyProfile.Business (This

contains the business
rules)
Root namespace: PublicSite

3) Assembly: PublicSite.MyProfile.Data (This contains

the data layer)
Root namespace: PublicSite

I also have my connection strings defined in the

application object. So, in
the main assembly, I can access the connection strings by

using
current.application("myConnection"). However, I need

to access the
Application object in my Business assembly. How can I

do that???

I tried to do this: Dim x as new

System.Web.httpContext.Current, but that
didn't work. When I use intellisense, I get the

following after System.Web:
{AspNetHostingPermision},

{AspNetHostingPermissionAttribute} and
{AspNetHostingPermissionLevel}

I believe that it's easy to make an argument to say that

one should never
try to access the asp.net application object from within

a business class,
but currently, we only use these objects for asp.net and

not windows
applications. (not that I'm making excuses.....)

Thank you very much for your help!

SteveS
ss*****@trendmls.com
.


Nov 18 '05 #5
Nov 18 '05 #6
Hello Steve,

Tried something similar in C# last evening... but it wouldnt let me compile it... having tried using System.web... didnt allow me to create the HttpConext...
finally i had put a similar post on security ng... and someone was kinda enough to suggest that i use
Principal from the Thread.CurrentPrincipal.IsInRole() to check the validaity for the call... have to try it later on during the evening or 2morrow...

Thread.CurrentPrincipal.IsInRole("role")

Happy holidays... and thanks,

HD

"SteveS" <ss*****@trendmls.com> wrote in message news:ua**************@TK2MSFTNGP09.phx.gbl...
I got it to work. Here's what I did:

1) Make sure there is a reference set to System.Web
2) Import System.Web in your class module
3) Use this code in your function:
Dim objHTTPApp As System.Web.HttpApplication
dim strConnection as string
strConnection = objHTTPApp.Context.Current.Application("MyConnecti on").ToString

This worked perfectly for me.

However, I have one question, if someone would like to answer it....

I'm not completely sure why I had to Import System.Web. First, I tried this but it didn't work:
strconnection = System.Web.HttpApplication.Context.Current.Applica tion("MyConnection").ToString
Why wouldn't this compile?

Happy Holidays,

SteveS
"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message news:O4**************@TK2MSFTNGP10.phx.gbl...
Steve,

Even i am having a similar issue...
writing a custom assembly which does serialization and lot of other junk...
want to check whether user is authorised to use the page
that assembly will be reference from within a class in ASP.NET app.

I tried to put a reference for System.Web;
not helpful... doesnt let me get the context...
looked a bit further and read something bout IHttpModule and IHttpHandler..
saying need to implement them in order get access to current context..

woud appreciate some help from someone who's done it before...

--
Regards,

HD

"SteveS" <ss*****@trendmls.com> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
That didn't work. I get the error "HttpContext is not declared" when I
try this:
Dim x as string = HttpContext.Current.Application("xxx").tostring .
.or..
Dim x as string =

System.Web.HttpContext.Current.Application("xxx"). Tostring

Here is my function:

Public Shared Function GetOpenConnection(ByVal WhichServer as ServerType)

as
SqlConnection
Dim conn as new SqlConnection
Select Case WhichServer
Case ServerType.TestServer
conn.ConnectionString =
HttpContext.Current.Application("MyConnectionStrin g")
End Select
... more code...
End Function

Any ideas???

Thanks!
"Tu-Thach" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...
You should be able to use HttpContext.Current without
problems. Make sure you are not declaring this in your
class member declaration, but in your method.

Tu-Thach

>-----Original Message-----
>Hello All. I have an asp.net application with 3
different assemblies. They
>are like this:
>
>1) Assembly: PublicSite (This contains the website UI)
> Root namespace: PublicSite
>
>2) Assembly: PublicSite.MyProfile.Business (This
contains the business
>rules)
> Root namespace: PublicSite
>
>3) Assembly: PublicSite.MyProfile.Data (This contains
the data layer)
> Root namespace: PublicSite
>
>I also have my connection strings defined in the
application object. So, in
>the main assembly, I can access the connection strings by
using
>current.application("myConnection"). However, I need
to access the
>Application object in my Business assembly. How can I
do that???
>
>I tried to do this: Dim x as new
System.Web.httpContext.Current, but that
>didn't work. When I use intellisense, I get the
following after System.Web:
>{AspNetHostingPermision},
{AspNetHostingPermissionAttribute} and
>{AspNetHostingPermissionLevel}
>
>I believe that it's easy to make an argument to say that
one should never
>try to access the asp.net application object from within
a business class,
>but currently, we only use these objects for asp.net and
not windows
>applications. (not that I'm making excuses.....)
>
>Thank you very much for your help!
>
>SteveS
>ss*****@trendmls.com
>
>
>.
>



Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ian | last post by:
The beginning of my assembly that I am getting the access error from looks like this. ********************************* Imports System.EnterpriseServices Imports System Imports...
1
by: Mark Miller | last post by:
I know this sounds really basic, but I'm having trouble with this within the VS.Net 2003 Pro IDE. I'm working with a VB.Net class library, and I'm having it reference a compiled assembly (a...
29
by: Patrick | last post by:
I have the following code, which regardless which works fine and logs to the EventViewer regardless of whether <processModel/> section of machine.config is set to username="SYSTEM" or "machine" ...
6
by: dbuchanan | last post by:
I have a Windows Forms application that accesses SQL Server 2k from a small local network. The application has been used for weeks on other systmes but a new install on a new machine retruns...
2
by: Orgbrat | last post by:
Is there a way to retrieve a WinForms application information such as Company, Product and Version from within a class library ( DLL ) that the Winforms application is using. Specificly the...
5
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callnetfrcom.asp The Joy of Interoperability Sometimes a revolution in programming forces you to abandon all...
9
by: JT | last post by:
Here is the overall structure I will be referring to: End-program ProvideWorkFlow.dll Forms and methods that properly manipulate calls to methods in AccessUtils AccessUtils (a web service)...
18
by: Rainer Queck | last post by:
Hello NG, I realized, that my application won't start, if a referenced assembly is missing. Basically this is understandable, but since I destribute my applictaion without a setup, it can...
0
by: Pheasant Plucker® | last post by:
Hi there, Not sure if this is the correct ng and I am not a programmer so excuse me but here goes...:-) We have a custom application that has a hook or calls either the Outlook calendar or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.