By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,354 Members | 907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,354 IT Pros & Developers. It's quick & easy.

how do I access the application object within another assembly?

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
Nov 18 '05 #6

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.