Can't access System.Web.HttpServerUtility in class

G

Guest

Hello All;

I can't access System.Web.HttpServerUtility from within a Class. I want to
have access to MapPath.

What I get are three options. They are:

AspNetHostingPermission
AspNetHostingPermissionAttributes
AspNetHostingPermissionLevel

What gives? What did I miss?

TIA,
 
P

Peter Rilling

I guess in light of Juan's explaination, never mind.

Peter Rilling said:
You need an instance of that class to access the members. Nothing is
static.
 
G

Guest

No. They're not there. The only options are:

AspNetHostingPermission
AspNetHostingPermissionAttributes
AspNetHostingPermissionLevel

Do you know why?

--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Juan T. Llibre said:
Try :

HttpContext.Current.Server.MapPath("filename.aspx")
 
J

Juan T. Llibre

What do you mean "They're not there", Joe ?

All you have to do, within any class file, is write

HttpContext.

and the available options *will* come up in Intellisense.

First, you choose HttpContext.Current and when you add another dot

HttpContext.Current.

You then select Server and get HttpContext.Current.Server
and then you add another dot :

HttpContext.Current.Server. and you select MapPath
which gives you HttpContext.Current.Server.MapPath

Then, all you need to do is add ("YourFileName.aspx")

If you don't do that, you won't see the correct options.




Joe said:
No. They're not there. The only options are:

AspNetHostingPermission
AspNetHostingPermissionAttributes
AspNetHostingPermissionLevel

Do you know why?
 
G

Guest

Peter,

If I type Dim s as System.Web. what appears in the Intellisense are the
following options:

AspNetHostingPermission
AspNetHostingPermissionAttributes
AspNetHostingPermissionLevel

I can't even get to the HttpCoontext or HttpServerUtilities class.

Any ideas?
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


Peter Rilling said:
I guess in light of Juan's explaination, never mind.
 
G

Guest

Hi Juan,

I mean that they're not there.

If I type "System" fiollowed by a period, the intellisense shows the options
within System. I select Web. After Web, I type a period and the
intellisense shows the following three options:

AspNetHostingPermission
AspNetHostingPermissionAttributes
AspNetHostingPermissionLevel
 
J

Juan T. Llibre

You don't need to type System.

All you nee to type is HttpContext.

Notice the period after HttpContext.
You *must* include the period for Intellisense to kick in.

Then, select Current, and so on, as listed in my previous post.
 
J

Juan T. Llibre

Let me amend that answer.

You *can * type System...but it's not needed.

If you *do* type System. , then you'll need to select

Web.
HttpContext.
Current.
Server.
and
MapPath
before you write (" to write in the filename you want a physical path for.
 
G

Guest

Juan,

Thanks. I understadn all of this. Please remember that I said that I am
tryignt o do this ina class. I am not tryign to do this in a webpage
cpde-behind.

From within the class, HttpContext is not even recognized.
 
G

Guest

Juan,

I understand how intellisense works. We don't need to go over that.

I tried typing HttpContext with the period. Nothing happens.

Remember that I am not doing this is in a webpage code-behind. I'm doing it
in a class (myClass.vb, not myPage.aspx).

This may have everything to do with where I am trying to do this.
 
P

Peter Rilling

Are you trying to use it from a different assembly from your main site? Is
so, you may need to add a reference to the System.Web.dll assembly.
 
J

Juan T. Llibre

re:
Remember that I am not doing this is in a webpage code-behind.
I'm doing it in a class (myClass.vb, not myPage.aspx).

I understand what you're saying, but it doesn't reflect what I experience.
I tested that in a class file, not in a code-behind aspx page.

re:
This may have everything to do with where I am trying to do this.

No, it does not.

Maybe you have a damaged VS ?
What version of VS are you using ?
 
G

Guest

Peter,

That's it! When I look in the references, I don't see System.Web; I see
System. I added System.Web and I'm on my way.

Thank youa nd thank you to Juan!.

Would you please help me to understand this? What I taek from this is that
having a reference to System is not adequate because the functionality that I
want is actually located in a different assembly. Is this correct? Did I
express it correctly?

Thanks again.
 
G

Guest

Juan,

Please see my reply to Peter. Thank you for your help. I appreciate your
efforts.

The problem was that I didn't have a refernece set to the System.Web assembly.
 
J

Juan T. Llibre

Hi, Joe.

Glad to see that Peter hit the nail on its head.

System and System.Web are two different assemblies.

See the System assembly :

http://beta.asp.net/QUICKSTART/util/classbrowser.aspx?namespace=System

Now, see the System.Web assembly :
http://beta.asp.net/QUICKSTART/util/classbrowser.aspx?namespace=System.Web

Two totally different assemblies...

Also, if you look in your .Net Framework directory :
drive:\WINDOWS\Microsoft.NET\Framework\vx.x.xxxxx
you'll see that there's different dll's for them : system.dll and system.web.dll

Glad to see that you're on the good track again.

;-)
 
Joined
May 22, 2008
Messages
1
Reaction score
0
This worked for me

var encodedValue = HttpContext.Current.Server.UrlEncode(value);

And this is not in a ascx.cs file, it is in a normal cs file...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top