Redirect non-existing sitemap.xml file to ASPX page

  • Thread starter Greg Collins [Microsoft MVP]
  • Start date
G

Greg Collins [Microsoft MVP]

Okay, this is driving me nuts now. I spent all last night researching newsgroup postings, web articles, etc.

Running multiple sites off the same shared hosting service, I want to be able to redirect a non-existing siteinfo.xml and sitemap.xml to appropriate ASPX pages that will return valid XML for the domain accessed.

I don't understand httpModules and httpHandlers very well but they don't seem to be what I need. There was discussion about using 404 redirects, but I can't seem to get this to work either.

What I currently have set up (which doesn't seem to work) is:

<location path="sitemap.xml">
<system.web>
<customErrors mode="On" defaultRedirect="~/RedirectSiteMap.aspx" />
</system.web>
</location>

or

<location path="sitemap.xml">
<system.web>
<customErrors mode="On" defaultRedirect="~/RedirectSiteMap.aspx">
<error statusCode="404" redirect="~/RedirectSiteMap.aspx" />
</customErrors>
</system.web>
</location>

This fails to work on localhost and on the deployed site. Ideas? What am I missing. I know others have said they have this working?

Running ASP.NET 2.0

Thanks!
 
K

Ken Cox [Microsoft MVP]

Hey Greg,

Your first code snippet works for me. When I try to access the non-existent
sitemap.xml file, ASP.NET redirects to the page RedirectSiteMap.aspx.

Could you explain more about what is going wrong? Does it not redirect at
all? What error do you see?

Ken
Microsoft MVP [ASP.NET]

"Greg Collins [Microsoft MVP]" <gcollins_AT_msn_DOT_com> wrote in message
Okay, this is driving me nuts now. I spent all last night researching
newsgroup postings, web articles, etc.

Running multiple sites off the same shared hosting service, I want to be
able to redirect a non-existing siteinfo.xml and sitemap.xml to appropriate
ASPX pages that will return valid XML for the domain accessed.

I don't understand httpModules and httpHandlers very well but they don't
seem to be what I need. There was discussion about using 404 redirects, but
I can't seem to get this to work either.

What I currently have set up (which doesn't seem to work) is:

<location path="sitemap.xml">
<system.web>
<customErrors mode="On" defaultRedirect="~/RedirectSiteMap.aspx" />
</system.web>
</location>

or

<location path="sitemap.xml">
<system.web>
<customErrors mode="On" defaultRedirect="~/RedirectSiteMap.aspx">
<error statusCode="404" redirect="~/RedirectSiteMap.aspx" />
</customErrors>
</system.web>
</location>

This fails to work on localhost and on the deployed site. Ideas? What am I
missing. I know others have said they have this working?

Running ASP.NET 2.0

Thanks!
 
G

Greg Collins [Microsoft MVP]

Strange. I'm not sure what could be wrong then.

For both localhost and remote host, I get the 404 page (forgive me for duplicating it here):

The page cannot be found
The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.
--------------------------------------------------------------------------------

Please try the following:

a.. Make sure that the Web site address displayed in the address bar of your browser is spelled and formatted correctly.
b.. If you reached this page by clicking a link, contact the Web site administrator to alert them that the link is incorrectly formatted.
c.. Click the Back button to try another link.
HTTP Error 404 - File or directory not found.
Internet Information Services (IIS)

--------------------------------------------------------------------------------

Technical Information (for support personnel)

a.. Go to Microsoft Product Support Services and perform a title search for the words HTTP and 404.
b.. Open IIS Help, which is accessible in IIS Manager (inetmgr), and search for topics titled Web Site Setup, Common Administrative Tasks, and About Custom Error Messages.
 
G

Greg Collins [Microsoft MVP]

Maybe this is entirely related, but I also recently tried adding default namespaces into the web.config file:

<pages>
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Configuration"/>
<add namespace="System.Data"/>
<add namespace="System.Data.SqlClient"/>
<add namespace="System.Web.UI"/>
<add namespace="System.Xml"/>
<add namespace="System.Xml.Xsl"/>
</namespaces>
</pages>

But when I tried to remove such references from my code behind pages:

using System;
using System.Web.UI;
using System.Xml;
using System.Xml.Xsl;

Then the page doesn't load anymore, telling me, for example:

Compiler Error Message: CS0246: The type or namespace name 'Page' could not be found (are you missing a using directive or an assembly reference?)


Perhaps these are related issues?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top