0

我有一个网站会在一段时间不活动后将用户注销。这是通过以下代码完成的:

 window.location = "./logout.aspx?timeout=true";

但是在过去的几天里,我三次收到以下异常:

System.Web.HttpException

The file '/NIR310/Person/logout.aspx' does not exist.

   at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
   at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
   at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
   at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
   at System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
   at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
   at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

起初错误似乎很明显,因为 logout.aspx 不包含在“Person”文件夹中,而是在根级别,但是为什么每次从“Person”文件夹中注销时都不会发生?我一遍又一遍地执行相同的程序,但错误几乎从未发生过。

有任何想法吗?

4

2 回答 2

2

将您的代码更改为以下内容:

window.location = "/logout.aspx?timeout=true";

通过删除“。” 从您总是要查找站点根目录的 URL 开始。

编辑:
正如评论中所述,Erikric 想要转到虚拟文件夹“NIR310”的根目录。

window.location = "/NIR310/logout.aspx?timeout=true";
于 2009-08-25T08:12:58.020 回答
1

您可以通过将完整解析的路径写入页面中来确保您始终拥有正确的站点根路径(假设您的注销页面位于根文件夹中):

window.location = '<%= ResolveUrl("~/logout.aspx?timeout=true")%>';

如果您的注销页面不在根文件夹中,请执行以下操作:

window.location = '<%= ResolveUrl("~/Pathtoyourpage/logout.aspx?timeout=true")%>';

这样即使您的开发和生产路径不同,重定向也会起作用。

希望这可以帮助。

于 2009-08-25T08:23:54.240 回答