By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,469 Members | 1,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,469 IT Pros & Developers. It's quick & easy.

Redirect non-existing sitemap.xml file to ASPX page

P: n/a
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!

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
Sep 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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_comwrote in message
news:eR**************@TK2MSFTNGP06.phx.gbl...
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!

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )

Sep 20 '06 #2

P: n/a
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.

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
Sep 20 '06 #3

P: n/a
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?

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )
Sep 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.