Server.MapPath在当前上下文中不存在 [英] Server.MapPath does not exist in the Current Context

查看:486
本文介绍了Server.MapPath在当前上下文中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#模型类,我试图在其中访问 .cshtml 页面,该页面应该是电子邮件格式模板。我正在使用以下代码:

I have a C# Model Class where I am trying to access a .cshtml page which is supposed to be an email format template. I'm using the following code:

string body = string.Empty;
using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailConfTemplate.cshtml")))
{
     body = reader.ReadToEnd();
}

但是我收到以下错误消息:

But i am getting the following error message:


名称服务器在当前上下文中不存在

The name Server does not exist in the current context

代码或 Server 类中的任何错误都不能在POCO类中访问。

Is there any error in the code or the Server class can't be accessed in POCO class. Please help.

推荐答案

要在.Net管道中执行它,您可以将其作为<$ c $中的实例进行查找。 c> HttpContext

To execute it inside a .Net pipeline, you can find it as an instance present in HttpContext

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

这篇关于Server.MapPath在当前上下文中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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