介绍ASP.NET的MVC项目部署到IIS6的几种思路(2)
第四步:修改默认的MainContent的内容部分为:
<script type="text/javascript" src="<%= Url.Content("~/Content/Js/jquery-1.3.2.min.js")%>"></script>
<!--<script type="text/javascript" src="<%= Url.Content("~/Scripts/jquery-1.3.2.min.js")%>" ></script>-->
<!--<script type="text/javascript" src="/Scripts/jquery-1.3.2.min.js"></script>-->
<!--<script type="text/javascript" src="http://localhost:50002/Scripts/jquery-1.3.2.min.js"></script>-->
<!-- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>-->
<script type="text/javascript">
function getWeather() {
//var URl = '<%= Url.Content("/Weather/GetWeather/")%>';
var URL = "/Weather/GetWeather/" + $("#Location").val();
$.get(URL, function(data) {
$("#Result").html(data);
});
}
</script>
<script type="text/javascript">
function getWeatherJSON() {
var URL = "/Weather/GetJsonWeather/";
$.getJSON(URL, { Location: $("#Location").val() }, function(data) {
var result = "";
$.each(data, function(index, d) {
if (d.WeatherImage != '') {
result += '<br \><img src="' + d.WeatherImage + '" > ';
result += d.Day;
result += ', High ' + d.MaxTemperatureF + 'F';
result += ', Low ' + d.MinTemperatureF + 'F';
}
});
$("#Result").html(result);
});
}
</script>
<div>
<input type="text" id="Location" style="width: 325px" value="New York" />
<input type="button" id="btnSubmit" value="Get Weather" onclick="javascript:getWeather();" />
<input type="button" id="btnSubmitJson" value="Get Weather JSON" onclick="javascript:getWeatherJSON();" />
<br />
<br />
<div id="Result">
</div>
</div>
<div>
<ul>
<li>
<%= Html.ActionLink("WeatherJQuery", "GetWeather", "Weather")%>
</li>
<li>
<%= Html.ActionLink("WeatherJSON", "GetJsonWeather", "Weather")%>
</li>
</ul>
</div>
注意,这里一个端口号为50002,是iis的端口,而不是vs2008内置的端口,
看图:
下面开始正式的部署:如果此时在浏览器中输入http://localhost:50002/,会提示404错误。出错原因如下:
This happens because IIS 6 only invokes ASP.NET when it sees a “filename extension” in the URL that’s mapped to aspnet_isapi.dll (which is a C/C++ ISAPI filter responsible for invoking ASP.NET). Since routing is a .NET IHttpModule called UrlRoutingModule, it doesn’t get invoked unless ASP.NET itself gets invoked, which only happens when aspnet_isapi.dll gets invoked, which only happens when there’s a .aspx in the URL. So, no .aspx, no UrlRoutingModule, hence the 404.
大意是:因为IIS6只对aspx文件才调用 aspnet_isapi.dll进行处理,而在默认的MVC设置里是无路径的,所以会出现404。有人说,为什么vs2008内建的浏览器会支持呢?那正是因为调用了aspnet_isapi.dll的缘故。所以我们在IIS6中只要通知iis,需要对该网站的地址url进行解析处理即可。