I'm working on a custom 404 page for a new public facing SharePoint site which is replacing our current non-SharePoint site. Customers may have bookmarks that will break on the new site, simply because '/Pages' is not in their bookmark's URL.
So, I'm creating a C# user control which is loaded by a web part, and that web part is added to www.mydomain.com/Pages/pagenotfound.aspx. The user control reads a querystring value (url) for the bookmarked page and replaces each '/' char, in turn, with /Pages/, and then checks to see if that page exists, using the following method:
protected bool checkPageExists(string url)
{
bool returnedBool = false;
SPSite site = SPContext.Current.Site;
SPWeb web = SPContext.Current.Web;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite ElevatedSite = new SPSite(site.ID))
{
using (SPWeb ElevatedWeb = ElevatedSite.OpenWeb(web.ID))
{
SPFile page = web.GetFile(url);
if (page.Exists)
returnedBool = true;
else
returnedBool = false;
}
}
});
return returnedBool;
}
let's say our bookmarked URL (without domain) is /us/training/default.aspx.
I loop through this string, changing each '/', one at a time, and then calling 'checkPageExists(url)' above.
the first two runs through work fine, for:
- /Pages/us/training/default.aspx
- /us/Pages/training/default.aspx
but the third possible replacement...
- /us/training/Pages/default.aspx
...gets to the if (page.Exists) line of my method above and then redirects the browser to my sites sign in page
I should point out that none of these 3 possible replacements to the URL will end up returning true for page.Exists, as I've not created a US training page yet. However, the result of my 404 page should be along the lines of "we tried to find your page, but failed", rather than asking the user to sign in.
Any ideas why this third replacement should prompt for a sign in? I thought that by running with elevated privileges, I'd get around any user permission issues, but apparently not.
Any help would be greatly appreciated.
(also, feel free to update the tags for the question, I have such as hard time figuring out the best ones to use)
Kevin

