开发者

App config asp.net

Let's say I have a class called AppConfig:

public static class AppConfig
{
    private static XDocument config = 

    public static AppConfig()
    {

    }
}

How do I XDocument.Load the ~App.Config file? Isn开发者_如何学Go't it something like Server.SOMETHING? What namespaces do I need to include>


XDocument.Load(HttpContext.Current.Server.MapPath("~/web.config")); 

is probably what you're looking for. This helper class "Server" lives on the "current" HttpContext inside the System.Web namespace, so add a

using System.Web;

to your code.

Marc


I think what is his problem, he is not able to get server class in his class

Server is property of the Page class that your page inherits from, it not a global. if you are trying to access from a class, use

HttpContext.Current.Server.MapPath("");

and add reference

using System.Web;

OR can be get directly

System.Web.HttpContext.Current.Server.MapPath("");


I'm not sure why you're trying to do that ... if you want to access the values in your web.config or app.config (for client apps) there is already a wrapper class set up to do that named My.Settings.

Those app.config and web.config files are a pain in the keester to deal with directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜