Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top