分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

HttpContext.Current.Server未将对象引用到实例

发布时间:2023-09-06 01:50责任编辑:熊小新关键词:暂无标签

问题描述:

在一些类库中需要读取当前系统的xml文件,当时用HttpContext.Current无法找到实例化对象

解决代码如下:

XmlDocument xml = new XmlDocument();
???????????//加载xml文件
???????????try
???????????{
???????????????if (HttpContext.Current != null)
???????????????{
???????????????????xml.Load(HttpContext.Current.Server.MapPath("~/Configs/CityAreas.xml"));
???????????????}
???????????????else
???????????????{ ???????????????????????????????
???????????????????xml.Load(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs\\CityAreas.xml"));
???????????????}
????????????
???????????}
???????????catch (Exception ex)
???????????{
???????????????Helper.ComHelper.CityDataLog("CityAreas配置有误,请及时检查!");
???????????}

HttpContext.Current.Server未将对象引用到实例

原文地址:https://www.cnblogs.com/pangzili/p/8870516.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved