我正在使用MVC 3、Visual Studio 2010和C# 4.0进行开发。我的应用程序在使用Visual Studio中的IIS Express时能正常工作,并且当部署到远程生产IIS 7.5服务器上时也能正常工作。
但是,当我在开发系统上切换到完整的IIS 7.5服务器时,我的两个控制器中的操作突然开始出现HTTP 404错误。其他控制器可以正常运行。这不管是从Visual Studio还是直接从IIS运行应用程序都会出现此问题。
我没有看到任何配置差异。
其中一个表现出这种行为的控制器是:
但是,当我在开发系统上切换到完整的IIS 7.5服务器时,我的两个控制器中的操作突然开始出现HTTP 404错误。其他控制器可以正常运行。这不管是从Visual Studio还是直接从IIS运行应用程序都会出现此问题。
我没有看到任何配置差异。
其中一个表现出这种行为的控制器是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Configuration;
using Mbrrace.ApplicationServices.Validation;
namespace Mbrrace.WebUI.Areas.Validation.Controllers
{
public class ValidationController : Controller
{
//
// GET: /Validation/Validation/
[HttpGet]
public JsonResult PostcodeCheck([Bind(Prefix = "perinatalView")]AddressViewModel model)
{
// postcode has already been checked for correct format
// now look it up to see if it exists
if (PostcodeChecks.CheckPostcodeExists(ConfigurationManager.ConnectionStrings["CommonCodeEntities"].ConnectionString, model.Postcode))
{
return Json(true, JsonRequestBehavior.AllowGet);
}
return Json("This postcode was not found in the database", JsonRequestBehavior.AllowGet);
}
[HttpPost]
public JsonResult PostcodeExtendedCheck(String Postcode)
{
// check if it exists or of it's sector exists (all but last two characters
string message = PostcodeChecks.PostcodeExtendedCheck(ConfigurationManager.ConnectionStrings["MbrraceCommonCodeEntities"].ConnectionString,
Postcode, Postcode.Substring(0, Postcode.Length - 2));
string success = (message.Length == 0) ? "OK" : "NO";
var result = new { Success = success, Message = message };
return Json(result, JsonRequestBehavior.AllowGet);
}
public class AddressViewModel
{
public string Postcode { get; set; }
}
}
}
在IIS Express和部署到IIS时,这个行为符合预期。但是当IIS连接到项目进行调试时,它会抛出404错误。
请问有人能解释一下为什么会产生404错误吗?