gpt4 book ai didi

c# - ASP.NET MVC 中的 “File does not exist”

转载 作者:行者123 更新时间:2023-11-30 21:58:48 24 4
gpt4 key购买 nike

我刚开始收到“文件不存在”异常。在 visual studio 中按下运行按钮后发生异常。据我所知,我的代码都没有被命中。应该打的代码部分是

public ActionResult Index() { 
return View("Index");
}

但该代码中的断点从未命中。 .. 我跟着 How to solve exception "File does not exist"?System.Web.HttpException File does not exist - Page loads just fine (ASP.NET)并编写了以下代码:

void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();

if (ex.Message == "File does not exist.")
{
var foo = Request.RawUrl;
var newEx = new Exception(string.Format("{0} {1}", ex.Message, HttpContext.Current.Request.Url.ToString()), ex);
}
}

现在,当我运行并点击这段代码时,foo 设置为“/”,newEX 为“文件不存在。http://localhost:63456/

有什么想法吗?

这是堆栈跟踪:

PishiWebSite.dll!PishiWebSite.MvcApplication.Application_Error(object sender, System.EventArgs e) Line 164 C# System.Web.dll!System.Web.HttpApplication.RaiseOnError() + 0xc6 bytes
System.Web.dll!System.Web.HttpApplication.RecordError(System.Exception error) + 0x40 bytes
System.Web.dll!System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(System.Exception error) + 0x101 bytes
System.Web.dll!System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback cb, object extraData) + 0xf8 bytes
System.Web.dll!System.Web.HttpRuntime.ProcessRequestInternal(System.Web.HttpWorkerRequest wr) + 0x284 bytes System.Web.dll!System.Web.HttpRuntime.ProcessRequestNoDemand(System.Web.HttpWorkerRequest wr) + 0x6e bytes
System.Web.dll!System.Web.HttpRuntime.ProcessRequest(System.Web.HttpWorkerRequest wr) + 0x47 bytes
WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Request.Process() + 0x188 bytes WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Microsoft.VisualStudio.WebHost.Connection conn) + 0x66 bytes
[Appdomain Transition]
WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Server.OnSocketAccept(object acceptedSocket) + 0xa1 bytes
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object state) + 0x3e bytes mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0xa7 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x16 bytes
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() + 0x60 bytes mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() + 0x149 bytes
mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() + 0x5 bytes [Native to Managed Transition]

同时在立即窗口中输入 Server.GetLastError().StackTrace.ToString() 给出:

at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response) at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath) at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

最佳答案

在某些情况下,visual studio 不会遇到有效的断点。包括 system.diagnostics 命名空间并使用 debugger.break() 强制断点。确定问题后从代码中删除。

https://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.aspx

关于c# - ASP.NET MVC 中的 “File does not exist”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29833978/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com