views:

221

answers:

2

Hi,

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?

+2  A: 
Zaagmans
He's using the . to go up a directory, isn't he? So surely he'd want `/NIR310/Person/logout.aspx?timeout=true`?
Kezzer
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.
Zaagmans
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
The answer I've provided does exactly what you ask. If you want something else, please rephrase the question.
Zaagmans
+1  A: 

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
Yup, this method is definitely more reliable than using static URL's.
Kezzer