使用Server.Mappath不当前上下文存在 [英] Server.MapPath does not exist in current context
问题描述
在我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屋!