使用Server.Mappath不当前上下文存在 [英] Server.MapPath does not exist in current context

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

问题描述

在我MVC4项目,我有空间

Inside my MVC4 project I have the namespace

prj.MVC4.Controllers

prj.MVC4.Controllers

在这里我使用使用Server.Mappath(..)没有问题和

where I'm using Server.MapPath(..) without problem and on

prj.MVC4.Models

prj.MVC4.Models

使用Server.Mappath( ...)不会对目前的情况下存在。

Server.MapPath(...) does not exist on current context.

我知道,使用Server.Mappath 位于的System.Web 和空间都和组装加入到类使用的System.Web System.Web.dll程序添加到PRJ。

I'm aware that Server.MapPath resides in System.Web and both namespace and assembly are added into class with using System.Web and System.Web.dll is added to the prj.

在<大骨节病>控制 + <大骨节病>。。我越来越 Microsoft.SqlServer 的建议命名空间的补充。

on Ctrl + .. I'm getting Microsoft.SqlServer as suggested namespace to add.

如何解决这一问题?

推荐答案

服务器是控制器的属性,在其他地方访问它在运行,你可以使用一个Web应用程序

Server is a property of the controller, to access it elsewhere while running a web application you can use

System.Web.HttpContext.Current.Server

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

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