c# - MVC 5 不适用于 IIS 7

标签 c# visual-studio-2012 iis-7 asp.net-mvc-5

我尝试在 IIS7 中运行我的 ASP.NET MVC5,但网站只显示我的 cshtml 文本。

我的配置:

GoWireless>Basic Settings>Select(.Net Framework Version: No Manage Console, Pipeline mode: Classic)

GoWireless>Directory Browsing>Enabled

Index.cshtml 只显示这段文字

@model IEnumerable @{ ViewBag.Title = "Active Directory"; } Active Directory

Welcome,@User.Identity.Name.Remove(0,User.Identity.Name.IndexOf("\") + 1)!

This is GoWireless active directory searcher, you can use the search box or click one of the employees in the left corner to view the employee details. If you want to search users that only exist in GoWireless\ActiveDirectory and not exist in GW_UTA\ActiveDirectory2 you can input and search one of his\her details (SamAccountName, GivenName, Surname, Email or EmployeeNumber) in full format into search-box.

Learn more

_Layout.cshtml 只显示这段文字

@model IEnumerable
Toggle navigation   Failed to load images
@User.Identity.Name
@using (Html.BeginForm("Index", "Home", FormMethod.Post)) {
@Html.TextBox("search", null, new { @class = "form-control", @placeholder = "Search..." })  
}
@foreach (var item in Model) {
class="active"} href='@Url.Action("Details", "Home", new { id = item.SamAccountName.Replace(".", "_") })'>@item.SamAccountName
ViewBag.count = 1; } @if (ViewBag.count != 1) { EasyAD.EasyAD ad = new EasyAD.EasyAD("dc1.gowireless.net:389", "gowireless\\ldapuser", "abc123!@#"); System.Data.DataTable dt = ad.GetUsers(ViewBag.search); var count = 0; while (count < dt.Rows.Count) { if (dt.Rows[count]["SamAccountName"].ToString() != null && dt.Rows[count]["SamAccountName"].ToString() !="") {
class="active"} href='@Url.Action("Details", "Home", new { id = dt.Rows[count]["SamAccountName"].ToString().Replace(".", "_") })'>@dt.Rows[count]["SamAccountName"]
} else { ViewBag.warning = 1; } count++; } if (dt.Rows.Count <= 0) { ViewBag.count = 0; } }
@RenderBody() @if (ViewBag.warning == 1) {
× Warning! someone is containing the employee @ViewBag.search without SamAccountName, Please check manually the GoWireless\\ActiveDirectory.
} @if (ViewBag.success == 1) {
× Well Done! @ViewBag.search is successfully updated in ga_uta\\activedirectory.
} @if (ViewBag.count == 0) {
× Heads Up! @ViewBag.search is not exist in GW_UTA or GoWireless, maybe you are missing something?
} @if (ViewBag.error == 1) {
Oh Snap!
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt est vitae ultrices accumsan. Aliquam ornare lacus adipiscing, posuere lectus et, fringilla augue.

Some Error Accured
}

应该是这样的

enter image description here

最佳答案

托管模块

bin 文件夹包含 MVC 的所有必要程序集(MVC 5 不需要作为先决条件部署,因为它是网站部署包的一部分)。

然而,出于某种原因,MVC 没有重写 URL 来为我的站点调用正确的处理程序。因此,在仔细阅读各种 Stackoverflow 文章和博客文章后,我终于找到了突破 this one on MSDN .它解释了如何使用 IIS 管理器的 GUI 将 UrlRoutingModule 显式添加到 web.config,即使它显示为已为我的站点安装:

enter image description here

在我取消选中“仅调用对 ASP.NET 应用程序或托管处理程序的请求” 复选框后,条目类型更改为本地(参见上面的屏幕截图)和相应的部分出现在我的 web.config 中。 IIS突然开始明白了<system.webServer>部分(我仍然不知道为什么),网站开始呈现 MVC View 。 See more at cdonner...

关于c# - MVC 5 不适用于 IIS 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26172040/

相关文章:

visual-c++ - 在 Jenkins 上构建时来自 VS2012 解决方案的 MSB4019

sql - VS2012 部署后脚本引用了其他几个脚本

java - 在 Microsoft IIS 7 中部署 War 文件

asp.net-mvc - SignalR 2.0 - IIS 虚拟目录中的 404

c# - 无法从反序列化数据中检索键和值信息

visual-studio-2012 - 为什么 TFS 内部版本号在 2012 年停止自动递增?

c# - Application.GetContentStream 为内容 Uri 返回 null

c# - 从 C# 添加 Windows 功能

javascript - ajax PUT 不传输数组

C# WPF - 没有获得焦点的弹出窗口