visual-studio 在 IIS 6 上部署 Asp.Net MVC 2 /C# 4.0 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2319498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:35:20  来源:igfitidea点击:

Deploying Asp.Net MVC 2 /C# 4.0 application on IIS 6

visual-studiovisual-studio-2010asp.net-mvc-2iis-6

提问by Mose

I got a problem migrating from VS.Net 2008/ MVC 1to VS.NET 2010(+C# 4.0) / MVC 2

我在从VS.Net 2008/ MVC 1迁移到VS.NET 2010(+C# 4.0) / MVC 2 时遇到问题

The web.config has been updated, the site runs well in Cassini, but my problem now is deploying on IIS 6.

web.config中已经更新,该网站是在卡西尼运行良好,但现在我的问题是在IIS 6部署。

I updated the web site to run using ASP.Net 4, but whatever URL I try, I always have a 404 error. It's as if the routing was not taken into account (yes, the wildcard mappinghas been done).

我更新了网站以使用ASP.Net 4运行,但是无论我尝试使用什么 URL,我总是遇到 404 错误。就好像没有考虑路由一样(是的,通配符映射已经完成)。

I do not understand this mess and could not google anything interesting... Thanks for your suggestions !

我不明白这个烂摊子,无法用谷歌搜索任何有趣的东西......感谢您的建议!

回答by Mose

Ok I got y answer (thanks to a colleague)

好的,我得到了答案(感谢一位同事)

When migrating from ASP.Net 2.0 to ASP.Net4.0, if you meet the same problem, then check in Web Service Extensionif ASP.Net v4 is Allowed.

从 ASP.Net 2.0 迁移到 ASP.Net4.0 时,如果遇到同样的问题,请检查Web Service Extensionif ASP.Net v4 is Allowed

In my case, after installing the .Net framework 4, it was prohibited.

就我而言,安装 .Net framework 4 后,它被禁止。

Will & Mark : thanks for your help, hope it will helps others.

Will & Mark : 感谢您的帮助,希望它会帮助其他人。

回答by Mark Bell

I think I know what's happening: on IIS6, as well as the wildcard mapping you will need a default document (Default.aspx) that routes folder requests to the MVC handler.

我想我知道发生了什么:在 IIS6 上,以及通配符映射,您将需要一个默认文档 (Default.aspx),它将文件夹请求路由到 MVC 处理程序。

There was one included with the MVC1 project templates, but it has been removedin MVC2.

MVC1 项目模板中包含一个,但它已在 MVC2 中删除

Default.aspx:

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="YourNameSpace._Default" %>

<%-- Please do not delete this file. It is used to ensure that ASP.NET MVC is activated by IIS when a user makes a "/" request to the server. --%>

and Default.aspx.cs:

Default.aspx.cs

using System.Web;
using System.Web.Mvc;
using System.Web.UI;

namespace YourNameSpace
{
    public partial class _Default : Page
    {
        public void Page_Load(object sender, System.EventArgs e)
        {
            // Change the current path so that the Routing handler can correctly interpret
            // the request, then restore the original path so that the OutputCache module
            // can correctly process the response (if caching is enabled).

            string originalPath = Request.Path;
            HttpContext.Current.RewritePath(Request.ApplicationPath, false);
            IHttpHandler httpHandler = new MvcHttpHandler();
            httpHandler.ProcessRequest(HttpContext.Current);
            HttpContext.Current.RewritePath(originalPath, false);
        }
    }
}

When you say "It's as if the routing was not taken into account", I suspect that it actually isn't, and this is your problem.

当你说“就好像没有考虑路由一样”时,我怀疑它实际上没有,这是你的问题。

回答by Joe de la Forms

This finally fixed it for me:

这终于为我解决了:

I commented earlier, and a wee bit prematurely. My comment to Mark B's post was getting my initial Index view to show up, but then I kept getting the 404 errors whenever I navigated to any other view.

我之前评论过,有点过早了。我对 Mark B 帖子的评论是让我的初始索引视图显示出来,但是每当我导航到任何其他视图时,我都会收到 404 错误。

I was also distracted by the green check mark approved solution in this particular forum, but I could not even see the web server extensions folder in IIS 6 on my desktop; therefore, I had no control from that stand point of enabling aspnet 4.0, though I made sure it was installed by performing running the following command line:

我也被这个特定论坛中绿色复选标记批准的解决方案分散了注意力,但我什至在我的桌面上看不到 IIS 6 中的 Web 服务器扩展文件夹;因此,从启用 aspnet 4.0 的角度来看,我无法控制,尽管我通过运行以下命令行确保它已安装:

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -i

Now for the actual piece that finally allowed me to navigate to the other views besides just my Home/Index:

现在对于最终允许我导航到除我的主页/索引之外的其他视图的实际部分:

In the Global.asax.csfile of your VS 2010 Solution, you will see code as follows in the RegisterRoutesmethod:

Global.asax.cs你的 VS 2010 解决方案的文件中,你会在RegisterRoutes方法中看到如下代码:

  routes.MapRoute(
      "Default", // Route name
      "{controller}/{action}/{id}", // URL with parameters
      new { controller = "Home", action = "Index", id = UrlParameter.Optional });

I simply added ".aspx" after the {action} section of the tag as follows:

我只是在标签的 {action} 部分后添加了“.aspx”,如下所示:

  routes.MapRoute(
      "Default", // Route name
      "{controller}/{action}.aspx/{id}", // URL with parameters
      new { controller = "Home", action = "Index", id = UrlParameter.Optional });

And ahla wahla Peanut Butter and Jelly sandwiches. :0)

还有 ahla wahla 花生酱和果冻三明治。:0)

回答by Spooles

If you want to do it in C#, just add the System.DirectoryServices reference and this piece should do the job nicely.

如果您想在 C# 中执行此操作,只需添加 System.DirectoryServices 引用,这部分应该可以很好地完成工作。

DirectoryEntry w3svc = new DirectoryEntry("IIS://localhost/W3SVC");
w3svc.Invoke("EnableWebServiceExtension", "ASP.NET v4.0.30319");
w3svc.CommitChanges();

HTH

HTH