The type or namespace name "Server" cannot be found (is the using command or assembly reference missing ?)

Source: Internet
Author: User

Today, I copied a code in webserice to a C # class and ran the compilation error.
DataBase = Server. MapPath ("data. mdb ");
Error:The type or namespace name "Server" cannot be found (is the using command or assembly reference missing ?)

But I did reference the namespace using System. Web. Why?
Because the complete path of the Server is System. Web. HttpContext. Current. Server. Using System. web is obviously not enough, but Server can be directly written into the class inherited from the built-in Page class. mapPath "data. mdb "), it should be because the Page class already contains these class paths.

The solution to these errors is summarized as follows:
1. Ensure correct assembly references:
Make sure that the referenced assembly contains the namespace. If you are developing in Visual Studio. NET, go to the project menu and click Add reference. On the. NET tab, select the Assembly that contains the namespace you want to import, or browse to the folder that contains the assembly. If you are using the command line compiler, add the corresponding switch (/reference) to the compilation statement ).
2. Correct namespace:
(1)*If you execute this statement from the class inherited by the Page class, you can simply use
DataBase = Server. MapPath ("data. mdb ");
(2) If
A) Place the using statement at the top of the code file containing the type reference, and ensure that the namespace is imported into the project:
Using System. Web;
DataBase = HttpContext. Current. Server. MapPath ("data. mdb ");
B) if there is no using statement, the reference to the type is fully Limited:
DataBase = System. Web. HttpContext. Current. Server. MapPath ("data. mdb ");

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.