Server.MapPath occurrences of object references not set to an object

Source: Internet
Author: User

This article is only to make friends who encounter similar problems less detours

ASP.
I call a custom class with a CS file on a page, and the custom class calls the System.Web.HttpContext.Current.Server.MapPath method, which produces an error message that does not set the object reference to an instance of the object. Originally thought to be a custom class calling another custom class question, searched for half a day without finding the answer

So want to call System.Web.HttpContext.Current.Server.MapPath directly with the custom class, found still not, but with inherited System.Web.UI.Page CS file to call the class System.Web.HttpContex T.current.server.mappath will not go wrong, finally found
System.Web.HttpContext.Current.Server.MapPath
(System.Web.HttpContext.Current.Request.MapPath is also) to be called by the ASPX, even if the class inherits the System.Web.UI.Page call will also error

DLL file to get the current path you have to find another way.

System.AppDomain.CurrentDomain.BaseDirectory can be used, effects such as D:\myweb\

System.AppDomain.CurrentDomain.BaseDirectory is to find the base directory.

When I use it, as shown in

Server.MapPath occurrences of object references not set to an object

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.