Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1382
  • Last Modified:

The type or namespace name 'Server' could not be found (are you missing a using directive or an assembly reference?)

I use "Server.UrlEncode" in my class, I also have the

using System.Web

directive. How can this sucker not be found?
0
RichardFox
Asked:
RichardFox
1 Solution
 
AerosSagaCommented:
did you import the system.web namespace?
0
 
AerosSagaCommented:
if not try using system.web.httpserverutility.urlencode
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
RichardFoxAuthor Commented:
AerosSaga, when you ask did I import the namespace, what do you mean? I thought the "using" directive was all I needed
0
 
AerosSagaCommented:
At the top of your class like so:

Imports System.Web.HttpServerUtility
Imports System.Security.Principal
Public Class _Default

Regards,

Aeros
0
 
ihenryCommented:

Is this compile or run-time error?

Server is a property of System.Web.UI.Page class which is a shortcut to instance of HttpServerUtility class. You shouldn't be able to make a method call like "Server.UrlEncode" if your class is not System.Web.UI.Page or inherits from that class. If that is the case use HttpServerUtility.UrlEncode() instead.

Page.Server Property
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebUIPageClassServerTopic.asp

HttpServerUtility.UrlEncode Method
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebHttpServerUtilityClassUrlEncodeTopic.asp


HTH
0
 
RichardFoxAuthor Commented:
Thanks folks, what really puzzled me was that i could call Server.UrlEncode in my Page_Load function (where the class is a child of System.Web.UI.Page), but not in another class which I defined myself. So I came to the same conclusion which jhenry spelled out, and qualified the UrlEncode function with System.Web.HttpUtility.UrlEncode()

THanks for the help
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now