0

I have a website that will log the user out after a while of inactivity. This is done by the following code:

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

But three times in the last couple of days I have received the following exception:

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)

At first the error seemed obvious since logout.aspx is not contained in the "Person" folder, but at the root level, but why doesn't it happen every time when I get logged out from the "Person" folder? I've done the same routine over and over again, but the error almost never occurs.

Any ideas?

erikric
  • 4,049
  • 8
  • 32
  • 44

2 Answers2

2

Change your code to the following:

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

By removing the '.' from the URL you are always going for the root of the site.

EDIT:
As stated in the comments Erikric wants to go to the root of the virtual folder 'NIR310'.

window.location = "/NIR310/logout.aspx?timeout=true";
RuudKok
  • 5,252
  • 2
  • 26
  • 27
  • He's using the . to go up a directory, isn't he? So surely he'd want `/NIR310/Person/logout.aspx?timeout=true`? – Kieran Senior Aug 25 '09 at 08:20
  • If he wants to go up a directory, shouldn't he be using .. then? But in his question he states the logout.aspx file is located at the root level. – RuudKok Aug 25 '09 at 08:26
  • Sorry, I was a bit unclear here. By root, I meant in the root folder of the virtual directory. The suggestion here didn't work, since it took me to serverName/logout.aspx – erikric Aug 25 '09 at 08:44
  • The answer I've provided does exactly what you ask. If you want something else, please rephrase the question. – RuudKok Aug 25 '09 at 08:59
1

You can make sure you always have the correct path to your site's root by writing the full resolved path into the page as follows (assuming your logout page is in the root folder):

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

If your logout page isn't in the root folder, do the following:

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

This way the redirect will work even if your development and production paths are different.

Hope this helps.

Paul Suart
  • 6,505
  • 7
  • 44
  • 65