httpcontext.current.server.mappath对象引用不设置到对象的实例 [英] httpcontext.current.server.mappath Object reference not set to an instance of an object

查看:240
本文介绍了httpcontext.current.server.mappath对象引用不设置到对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是类中的以下代码:

I am using the following code within a class:

string filePath = HttpContext.Current.Server.MapPath("~/email/teste.html");

文件teste.html是文件夹

The file teste.html is in the folder

但是,当它打开正在生成以下错误的文件:

But when it will open the file is being generated the following error:

对象引用未设置到对象的实例。

Object reference not set to an instance of an object.

你知道吗?!

PS对不起我的英文不好!

p.s. Sorry my bad english!

推荐答案

不要使用使用Server.Mappath。这是缓慢的。使用此相反, HttpRuntime.AppDomainAppPath 。 。只要你的网站正在运行,此属性始终为您提供

Don't use Server.MapPath. It's slow. Use this instead, HttpRuntime.AppDomainAppPath. As long as your web site is running, this property is always available to you.

然后使用它是这样的:

string filePath = Path.Combine(HttpRuntime.AppDomainAppPath, "email/teste.html");

这篇关于httpcontext.current.server.mappath对象引用不设置到对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆