banComplete Guide: Fixing IIS 404 Errors and Database Connection Issues for ASP.NET Websites

Complete Guide: Fixing IIS 404 Errors and Database Connection Issues for ASP.NETarrow-up-right Websites

Introduction

When migrating an ASP.NETarrow-up-right website from a live server to a local development environment, you may encounter various issues including 404 errors on internal pages, database connection failures, and stored procedure execution errors. This comprehensive guide walks through the step-by-step troubleshooting process to resolve these common issues.


Table of Contents

  1. Understanding the Problem

  2. Fix 1: URL Rewriting for Friendly URLs

  3. Fix 2: Database Connection Issues

  4. Fix 3: Stored Procedure Schema Issues

  5. Fix 4: Character Encoding Problems

  6. Prevention and Best Practices


Understanding the Problem

When testing a site locally with a custom domain binding (e.g., http://yourdomain.com), you might encounter:

  • 404 errors when accessing friendly URLs like /about-us

  • Database connection failures

  • "Could not find stored procedure" errors even though the procedure exists

  • Garbled text with characters like â€oe appearing

These issues typically stem from four main areas:

  1. Missing URL rewrite rules in IIS

  2. Incorrect database connection strings

  3. SQL Server schema qualification problems

  4. File encoding issues


Fix 1: URL Rewriting for Friendly URLs

The Problem

When accessing http://yourdomain.com/about-us, IIS returns a 404 error with:

  • Handler: StaticFile

  • Physical Path: C:\inetpub\wwwroot\httpdocs\about-us

This indicates IIS is treating the request as a physical folder/file rather than passing it to ASP.NETarrow-up-right for processing.

The Solution

Step 1: Install URL Rewrite Module for IIS

Download and install the URL Rewrite Module from Microsoft:

Step 2: Verify Installation

Open IIS Manager → Select your site → Look for URL Rewrite icon in the features view.

Step 3: Configure Rewrite Rules in web.config

Add the following rewrite rules to your web.config:

xml

Key Configuration Points:

Setting

Purpose

runAllManagedModulesForAllRequests="true"

Routes all requests through ASP.NETarrow-up-right pipeline

stopProcessing="true"

Prevents further rule processing after a match

negate="true"

Skips rewrite if physical file/directory exists


Fix 2: Database Connection Issues

The Problem

Your application fails to connect to the database with errors like:

  • Could not find stored procedure

  • Login failed for user

  • Network-related errors

The Solution

Step 1: Verify Database Connectivity

Test the connection using SQLCMD:

cmd

Step 2: Update Connection Strings

Ensure your web.config has the correct database connection details:

xml

Step 3: Test the Database Connection

Create a diagnostic ASPX page:

aspx


Fix 3: Stored Procedure Schema Issues

The Problem

Your stored procedure exists but cannot be found:

text

Yet the procedure appears in sys.objects:

sql

Root Cause

The stored procedure exists in a non-default schema. When a stored procedure is called without a schema prefix, SQL Server looks in the default schema (typically dbo). If the procedure was created in a custom schema, it won't be found.

The Solution

Step 1: Find the Actual Schema

cmd

Example output:

text

Step 2: Apply One of These Fixes

Option A: Set Default Schema for User (Recommended)

cmd

Example:

cmd

Option B: Update Application Code

Change stored procedure calls to include the schema prefix:

csharp

Option C: Create a Wrapper Procedure

cmd

Step 3: Verify the Fix

cmd


Fix 4: Character Encoding Problems

The Problem

Text appears garbled with characters like â€oe, ”, or ‘ instead of proper quotes.

Root Cause

  • Content was copied from Microsoft Word which uses "smart quotes" (“ ” and ‘ ’)

  • The file encoding is UTF-8 but the browser interprets it as ANSI/ISO-8859-1

The Solution

Option A: Set Correct Encoding in web.config

xml

Option B: Add Meta Charset to ASPX Pages

html

Option C: Fix the Text Content

Replace smart quotes with straight quotes:

Wrong Character

Correct Replacement

â€oe or

"

” or

"

‘ or

'

’ or

'

Example:

html

Option D: Save Files with UTF-8 Encoding

Using Notepad++:

  1. Open the file

  2. Click EncodingEncode in UTF-8 without BOM

  3. Save the file

Using VS Code:

  1. Open the file

  2. Click on the encoding indicator in the bottom bar

  3. Select Save with EncodingUTF-8


Prevention and Best Practices

1. URL Rewriting

  • Always use rewrite (not redirect) for friendly URLs to keep the URL clean

  • Test rewrite rules with stopProcessing="true" to avoid conflicts

  • Keep generic rules at the bottom of your rules list

2. Database Connections

  • Use Windows Authentication when possible for local development

  • Store connection strings securely; never commit production credentials to version control

  • Use separate connection strings for development and production:

xml

3. Database Schemas

  • Always use schema prefixes in stored procedure calls: schema.procedure_name

  • Set appropriate default schemas for database users

  • Document custom schemas in your application documentation

4. Character Encoding

  • Always use UTF-8 without BOM for web files

  • Avoid copying directly from Microsoft Word; use Notepad as an intermediary

  • Set consistent encoding in your development environment

5. Diagnostic Tools

Create a diagnostic page to test your configuration:

aspx


Summary

Issue

Symptom

Solution

404 on friendly URLs

Handler: StaticFile

Install URL Rewrite module; add rewrite rules

Database connection

Login failed / timeout

Verify connection string; test with SQLCMD

Stored procedure not found

Procedure exists but can't execute

Set default schema or use schema prefix

Garbled text

â€oe characters appear

Set UTF-8 encoding; replace smart quotes


Quick Reference Commands

cmd


Conclusion

Migrating an ASP.NETarrow-up-right application to a local development environment requires careful attention to URL rewriting, database connectivity, schema handling, and file encoding. By systematically addressing each of these areas, you can successfully set up a functional local testing environment that mirrors your production configuration.

Remember to:

  1. Install required IIS modules (URL Rewrite)

  2. Verify database connectivity before assuming schema issues

  3. Check schema qualification when stored procedures can't be found

  4. Maintain consistent file encoding across your project

  5. Create diagnostic tools to quickly identify issues

With these fixes applied, your local site should function identically to the production environment, allowing for safe development and testing.

Last updated