Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Asp.Net MVC-无法开始监视文件更改_C#_Asp.net Mvc - Fatal编程技术网

C# Asp.Net MVC-无法开始监视文件更改

C# Asp.Net MVC-无法开始监视文件更改,c#,asp.net-mvc,C#,Asp.net Mvc,我尝试使用ASP.NETMVC编写自己的CMS,并在DB中存储html视图。我在internet上通过教程创建了自定义虚拟路径提供程序 MyVirtualPathProvider代码: using System.Linq; using System.Text; using System.Web.Hosting; using SgCms.Dal.Concrete; using SgCms.DomainModels; namespace SgCms.ViewFactory { public

我尝试使用ASP.NETMVC编写自己的CMS,并在DB中存储html视图。我在internet上通过教程创建了自定义虚拟路径提供程序

MyVirtualPathProvider代码:

using System.Linq;
using System.Text;
using System.Web.Hosting;
using SgCms.Dal.Concrete;
using SgCms.DomainModels;

namespace SgCms.ViewFactory
{
    public class SgCmsVirtualPathProvider : VirtualPathProvider
    {
        public override bool FileExists(string virtualPath)
        {
            var view = GetViewFromDatabase(virtualPath);

            if (view == null)
            {
                return base.FileExists(virtualPath);
            }
            else
            {
                return true;
            }
        }

        public override VirtualFile GetFile(string virtualPath)
        {
            var view = GetViewFromDatabase(virtualPath);

            if (view == null)
            {
                return base.GetFile(virtualPath);
            }
            else
            {
                byte[] content = ASCIIEncoding.ASCII.
                    GetBytes(view.InnerHtml);
                return new SgCmsVirtualFile
                    (virtualPath, content);
            }
        }

        private View GetViewFromDatabase(string virtualPath)
        {
            return PageBuilder(virtualPath);
        }

        private View PageBuilder(string path)
        {
            var virtualPath = path.Replace("~", "");

            DataContext db = new DataContext();
            var view = from v in db.Views
                where v.Path == virtualPath
                select v;

            var res = view.SingleOrDefault();

            return res;
        }
    }
}
using System.IO;
using System.Web.Hosting;

namespace SgCms.ViewFactory
{
    public class SgCmsVirtualFile : VirtualFile
    {
        private byte[] viewContent;

        public SgCmsVirtualFile(string virtualPath,
            byte[] viewContent) : base(virtualPath)
        {
            this.viewContent = viewContent;
        }

        public override Stream Open()
        {
            return new MemoryStream(viewContent);
        }
    }
}
MyVirtualFile代码:

using System.Linq;
using System.Text;
using System.Web.Hosting;
using SgCms.Dal.Concrete;
using SgCms.DomainModels;

namespace SgCms.ViewFactory
{
    public class SgCmsVirtualPathProvider : VirtualPathProvider
    {
        public override bool FileExists(string virtualPath)
        {
            var view = GetViewFromDatabase(virtualPath);

            if (view == null)
            {
                return base.FileExists(virtualPath);
            }
            else
            {
                return true;
            }
        }

        public override VirtualFile GetFile(string virtualPath)
        {
            var view = GetViewFromDatabase(virtualPath);

            if (view == null)
            {
                return base.GetFile(virtualPath);
            }
            else
            {
                byte[] content = ASCIIEncoding.ASCII.
                    GetBytes(view.InnerHtml);
                return new SgCmsVirtualFile
                    (virtualPath, content);
            }
        }

        private View GetViewFromDatabase(string virtualPath)
        {
            return PageBuilder(virtualPath);
        }

        private View PageBuilder(string path)
        {
            var virtualPath = path.Replace("~", "");

            DataContext db = new DataContext();
            var view = from v in db.Views
                where v.Path == virtualPath
                select v;

            var res = view.SingleOrDefault();

            return res;
        }
    }
}
using System.IO;
using System.Web.Hosting;

namespace SgCms.ViewFactory
{
    public class SgCmsVirtualFile : VirtualFile
    {
        private byte[] viewContent;

        public SgCmsVirtualFile(string virtualPath,
            byte[] viewContent) : base(virtualPath)
        {
            this.viewContent = viewContent;
        }

        public override Stream Open()
        {
            return new MemoryStream(viewContent);
        }
    }
}
我希望通过如下路径从DB获取视图:

我编写了自定义路由,现在所有请求都由一个操作处理。 甚至,当调用GetViewFromDatabase时,它也会得到我想要的视图。 但不幸的是,我还有一个例外:

目录“c:\users\nikita litvinenko\documents\visual studio 2017\Projects\SgCms\SgCms.Web\Views\Main”不存在。无法开始监视文件更改。 描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源

异常详细信息:System.Web.HttpException:目录“c:\users\nikita litvinenko\documents\visual studio 2017\Projects\SgCms\SgCms.Web\Views\Main”不存在。无法开始监视文件更改

源错误:

在执行当前web请求期间生成了未经处理的异常。有关异常的起源和位置的信息可以使用下面的异常堆栈跟踪来识别 堆栈跟踪: [HttpException(0x80070002):目录“c:\users\nikita litvinenko\documents\visual studio 2017\Projects\SgCms\SgCms.Web\Views\Main”不存在。无法开始监视文件更改。] System.Web.FileChangesMonitor.FindDirectoryMonitor(String dir,Boolean addIfNotFound,Boolean throwOnError)+589 System.Web.FileChangesMonitor.StartMonitoringPath(字符串别名、FileChangeEventHandler回调、FileAttributesData和fad)+655 System.Web.Caching.CacheDependency.Init(布尔值isPublic,字符串[]filenamesArg,字符串[]cachekeysArg,CacheDependency,DateTime utcStart)+2582 System.Web.Hosting.MapPathBasedVirtualPathProvider.GetCacheDependency(字符串virtualPath,IEnumerable virtualPathDependencies,日期时间utcStart)+400 System.Web.Hosting.virtualPath Provider.GetCacheDependency(字符串virtualPath,IEnumerable virtualPath Dependencies,DateTime utcStart)+36 System.Web.Hosting.VirtualPath Provider.GetCacheDependency(VirtualPath VirtualPath,IEnumerable VirtualPath Dependencies,DateTime utcStart)+38 System.Web.Compilation.MemoryBuildResultCache.CacheBuildResult(字符串cacheKey、BuildResult结果、Int64哈希代码、DateTime utcStart)+68 System.Web.Compilation.BuildManager.CacheBuildResultInternal(字符串cacheKey、BuildResult结果、Int64哈希代码、DateTime utcStart)+70 System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath VirtualPath)+10180802 System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath、Boolean noBuild、Boolean allowCrossApp、Boolean allowBuildInPrecompile、Boolean throwIfNotFound、Boolean EnsureUpdate)+294 System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext上下文、VirtualPath VirtualPath、Boolean noBuild、Boolean allowCrossApp、Boolean allowBuildInPrecompile、Boolean throwIfNotFound、Boolean EnsureUpdate)+103 System.Web.Compilation.BuildManager.GetVirtualPath对象工厂(VirtualPath VirtualPath,HttpContext上下文,布尔allowCrossApp,布尔throwIfNotFound)+165 System.Web.Compilation.BuildManager.GetCompiledType(VirtualPath VirtualPath)+15 System.Web.Compilation.BuildManager.GetCompiledType(字符串virtualPath)+29 System.Web.Mvc.buildmanagerRapper.System.Web.Mvc.IBuildManager.GetCompiledType(字符串virtualPath)+6 System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext,TextWriter)+54 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext上下文)+291 System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext ControllerContext,ActionResult ActionResult)+13 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1过滤器、Int32过滤器索引、ResultExecutingContext预文本、ControllerContext ControllerContext、ActionResult ActionResult)+56
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1过滤器、Int32过滤器索引、ResultExecutingContext预文本、ControllerContext ControllerContext、ActionResult ActionResult)+420 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext ControllerContext,IList
1过滤器,ActionResult ActionResult)+52
System.Web.Mvc.Async.c__显示类2B.b__1c()+173
System.Web.Mvc.Async.c__显示Class21.b__1e(IAsyncResult asyncResult)+100
System.Web.Mvc.Async.WrappedAsyncResult
1.CallEndDelegate(IAsyncResult asyncResult)+10 System.Web.Mvc.Async.WrappedAsyncResultBase
1.End()+49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)+27
System.Web.Mvc.Controller.b_u1d(IAsyncResult asyncResult,ExecuteCorerate innerState)+13
System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult)+29 System.Web.Mvc.Async.WrappedAsyncResultBase
1.End()+49
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+36
System.Web.Mvc.Controller.b_u15(IAsyncResult asyncResult,Controller-Controller)+12
System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult)+22 System.Web.Mvc.Async.WrappedAsyncResultBase
1.End()+49
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)+26
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)+10
System.Web.Mvc.MvcHandler.b