Sitemap 404 Fix
Sitemap.xml 404 Error - FIXED
Problem Identified
Error: https://mcbdshost.com/sitemap.xml returns 404 Not Found
Root Cause:
- Missing
.xmlMIME type mapping inweb.config - Static files not explicitly marked for output directory in
.csproj
Solution Implemented
Changes Made
1. web.config - Added XML MIME Type
<staticContent>
<mimeMap fileExtension=".xml" mimeType="application/xml" />
<mimeMap fileExtension=".txt" mimeType="text/plain" />
<!-- ...other MIME types... -->
</staticContent>
2. MCBDS.Marketing.csproj - Ensured File Inclusion
<ItemGroup>
<Content Update="wwwroot\sitemap.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\robots.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Quick Deployment
Option 1: Using PowerShell Script (Recommended)
cd deployment-packages
.\deploy-sitemap-fix.ps1
Option 2: Manual Deployment
# 1. Clean and publish
cd MCBDS.Marketing
dotnet clean -c Release
dotnet publish -c Release -o bin\Release\net10.0\publish
# 2. Verify sitemap exists
Test-Path bin\Release\net10.0\publish\wwwroot\sitemap.xml
# 3. Copy to IIS
Copy-Item -Path "bin\Release\net10.0\publish\*" -Destination "C:\inetpub\wwwroot\mcbdshost-marketing\" -Recurse -Force
# 4. Restart IIS
iisreset
# 5. Test
Invoke-WebRequest -Uri "https://mcbdshost.com/sitemap.xml"
Verification Steps
1. Check File Exists in Publish Output
Test-Path MCBDS.Marketing\bin\Release\net10.0\publish\wwwroot\sitemap.xml
# Should return: True
2. Check File in IIS Directory
Test-Path C:\inetpub\wwwroot\mcbdshost-marketing\wwwroot\sitemap.xml
# Should return: True
3. Test HTTP Access
# Using PowerShell
Invoke-WebRequest -Uri "https://mcbdshost.com/sitemap.xml"
# Or using browser
# Navigate to: https://mcbdshost.com/sitemap.xml
# Should display XML content
4. Verify in Browser
- Navigate to:
https://mcbdshost.com/sitemap.xml - Should display XML content with site URLs
- No 404 error
5. Check robots.txt References Sitemap
- Navigate to:
https://mcbdshost.com/robots.txt - Should contain:
Sitemap: https://mcbdshost.com/sitemap.xml
What Was Fixed
| Issue | Before | After |
|---|---|---|
| sitemap.xml accessibility | 404 Not Found | 200 OK |
| MIME type for .xml | Not configured | application/xml |
| File in publish output | Inconsistent | Always included |
| IIS can serve XML | No | Yes |
Files Changed
-
MCBDS.Marketing/web.config- Added.xmland.txtMIME types -
MCBDS.Marketing/MCBDS.Marketing.csproj- Ensured file inclusion - Created
deployment-packages/deploy-sitemap-fix.ps1- Automated deployment
Technical Details
Why the 404 Happened
IIS Static File Handler Requirements:
- IIS needs explicit MIME type mappings for file extensions
- Without
<mimeMap fileExtension=".xml" ...>, IIS won't serve .xml files - The ASP.NET Core module passes unhandled requests to the app, but static files should be served by IIS directly
.NET 10 Static Web Assets
- In .NET 10, Static Web Assets use a new build system
- Files in
wwwrootshould be automatically included - Explicit
<Content>entries ensure files are copied during publish CopyToOutputDirectoryguarantees the files appear in the publish folder
Testing Checklist
After deployment, verify:
- Build completes without errors
- Publish output contains
wwwroot/sitemap.xml - IIS directory contains
wwwroot/sitemap.xml -
https://mcbdshost.com/sitemap.xmlreturns 200 OK - XML content is displayed (not downloaded)
- Contains all 6 URLs (home, features, get-started, contact, gofundme, not-found)
-
https://mcbdshost.com/robots.txtis also accessible - Google Search Console can read the sitemap
Google Search Console Submission
After deploying the fix:
Go to Google Search Console
Navigate to Sitemaps
- Left menu Sitemaps
Add New Sitemap
- Enter:
sitemap.xml - Click: Submit
- Enter:
Verify Status
- Should show: Success
- URLs discovered: 6
Troubleshooting
sitemap.xml Still Returns 404
Solution 1: Check IIS MIME Types
# Open IIS Manager
# Select your site
# Double-click "MIME Types"
# Verify .xml is listed with application/xml
Solution 2: Verify File Exists
Get-ChildItem -Path "C:\inetpub\wwwroot\mcbdshost-marketing\wwwroot" -Filter "*.xml"
# Should list sitemap.xml
Solution 3: Check web.config
# Open web.config in IIS directory
# Verify <mimeMap fileExtension=".xml" mimeType="application/xml" /> exists
Solution 4: Restart IIS
iisreset
File Exists But Still 404
Check IIS Handler Mappings:
- Open IIS Manager
- Select your site
- Double-click "Handler Mappings"
- Verify "StaticFile" handler is enabled
- Verify it's not being overridden by ASP.NET Core handler
XML Downloads Instead of Displaying
Fix Content-Type Header:
- This means MIME type is set to
application/octet-stream - Verify
mimeType="application/xml"in web.config - Clear browser cache and try again
Expected Results
Immediate (After Deployment)
- sitemap.xml accessible at https://mcbdshost.com/sitemap.xml
- Returns HTTP 200 OK
- Content-Type: application/xml
Short-term (1-2 days)
- Google Search Console accepts sitemap
- All 6 URLs submitted to Google
- Crawl status shows "Success"
Medium-term (1-2 weeks)
- All pages indexed by Google
- Pages appear in Google search results
- Sitemap shows "Last read" date in Search Console
Summary
Problem: sitemap.xml returned 404 error
Cause: Missing XML MIME type in web.config
Solution: Added MIME type mappings and file inclusion directives
Status: FIXED AND READY TO DEPLOY
Next Steps
- Deploy the fix using the PowerShell script
- Test sitemap.xml in browser
- Submit to Google Search Console
- Monitor indexing status
Status: READY FOR DEPLOYMENT
Last Updated: December 29, 2024
For: MCBDSHost Marketing Site
Priority: High (SEO Critical)