【发布时间】:2023-03-27 16:05:01
【问题描述】:
我在 Windows 2003 服务器上使用 IIS 6,并试图在该机器上安装一个 MVC2 项目。这样做我遇到了噩梦般的问题! 我已经查阅了大量关于该做什么的参考资料,而不是一个单独的作品。 (它们适用于 MVC1 项目,因为我有一些项目已经在使用上述解决方案)。
是否有人对使用 IIS 6 的 MVC2 项目需要做什么有任何提示/提示/想法?我肯定会为此而烦恼。
我已经在我的两台开发服务器上进行了尝试,都得到了相同的结果。最接近服务页面的是错误页面“对象引用未设置为对象的实例”,但是,该页面具有被忽略的 try/catch 块,因此我认为它不会在控制器,我认为这是说控制器是错误的。 (供参考,有问题的错误指向 HomeController.cs 文件)。
我尝试过的:
- 通配符映射
- 将路由更改为 {controller}.mvc
- 将路由更改为 {controller}.aspx
- 将 .mvc 扩展名添加到 IIS
- 在 Global.asax 中修改路由
到目前为止,这个项目中有很多代码,所以我只会发布应该提供的第一页:
母版页:
<div class="page">
<div id="header">
<div id="title">
<h1>Meritain RedCard Interface 2.0</h1>
</div>
<!--
This is the main menu. Each security role will have access to certain buttons.
-->
<div id="menucontainer">
<% if (Session["UserData"] != null)
{ %>
<% if (/*User Security Checks Out*/)
{ %>
<ul id="menu">
<li><%= Html.ActionLink("Home", "Index", "Home")%></li>
<li><%= Html.ActionLink("Selection", "Index", "Select", new { area = "Selector" }, null)%></li>
<li><%= Html.ActionLink("Audit", "Index", "Audit", new { area = "Auditor" }, null)%></li>
<li><%= Html.ActionLink("Setup", "Index", "Setup", new { area = "Setup" }, null)%></li>
<li><%= Html.ActionLink("About", "About", "Home")%></li>
</ul>
<% } %>
<% } %>
</div>
</div>
<div id="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
<div id="footer">
</div>
</div>
</div>
Default.aspx.cs:[我将此文件添加为潜在的解决方案,因为它适用于 MVC 1]
protected void Page_Load(object sender, EventArgs e)
{
string originalPath = Request.Path;
HttpContext.Current.RewritePath(Request.ApplicationPath, false);
IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(HttpContext.Current);
HttpContext.Current.RewritePath(originalPath, false);
}
HomeController.cs:
public ActionResult Index()
{
loadApplication();
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View();
}
public ActionResult About()
{
return View();
}
private void loadApplication()
{
Session["UserData"] =
CreateUserSecurity(HttpContext.User.Identity.Name.ToString());
}
我没有列出 CreateUserSecurity 方法,但它所做的只是使用用户名调用数据库并返回数据库中与用户名匹配的记录。
编辑:添加代码和我迄今为止尝试过的内容(根据要求)。
【问题讨论】:
-
事件日志中是否有任何可能有帮助的内容?
-
@mmacaulay - 事件日志中完全没有记录。
-
请在您的问题中输入您尝试过的内容以及您正在使用的代码。
-
你为什么要把东西放在
Page_Load?你为什么使用Page_Load?这不是 ASP.NET。 -
page_load 是我在 MVC1 应用程序中必须使用的一个技巧。这只是我让它发挥作用的尝试之一。
标签: asp.net iis asp.net-mvc-2 iis-6