新鲜Windows + VS2012 = MVC3问题

时间:2012-10-04 20:46:26

标签: c# asp.net-mvc-3 http-post visual-studio-2012 iis-express

我刚刚在运行VS2012 / VS2010的PC上安装了全新的Windows 7。我有一个MVC3项目运行得很好,然后我将它拉到这台PC上运行。该项目仍然在这台PC上编译,我可以在工作室(2010或2012)中运行应用程序时浏览我的网站,但是当我尝试在任何视图中从任何表单发布POST并通过URL传递ID时,如下所示:

    <form id="ScriptForm" action="/MyApp/ControllerName/ActionName/@ViewBag.IDNumber" method="post">
    ...
    </form>

......我得到了this error。我做了一些挖掘和游戏试图解决这个问题,最终采取这些步骤来尝试解决:

  1. 通过“控制面板”中的“Windows组件”表单实际安装了ASP.NET
  2. 更改了应用程序以使用IIS Express
  3. 好吧,当我将其更改为在IIS Express下运行时,我开始遇到其他错误。

    HTTP Error 404.0 - Not Found
    The resource you are looking for has been removed, had its name changed, or is 
    temporarily unavailable.
    
    Most likely causes:
    The directory or file specified does not exist on the Web server.
    The URL contains a typographical error.
    A custom filter or module, such as URLScan, restricts access to the file.
    
    Things you can try:
    Create the content on the Web server.
    Review the browser URL.
    Check the failed request tracing log and see which module is calling SetStatus. For more information, click here.
    
    Detailed Error Information:
    Module     IIS Web Core
    Notification       MapRequestHandler
    Handler    StaticFile
    Error Code     0x80070002
    Requested URL      http://localhost:51596/MyApp/ControllerName/ActionName/1
    Physical Path      C:\CODE\MyApp\ControllerName\ActionName\1
    Logon Method       Anonymous
    Logon User     Anonymous
    Request Tracing Directory      C:\Users\cbarlow\Documents\IISExpress\TraceLogFiles\MYAPP
    
    More Information:
    This error means that the file or directory does not exist on the server. Create the file or directory and try the request again.
    View more information »
    

    这几乎就好像它没有意识到这是一条路线,并且正在尝试将URL解析为物理文件(如1.html),这显然不存在。但为什么不是“做MVC事情”并使用路线?我在global.asax中有这个:

      public static void RegisterRoutes(RouteCollection routes)
      {
         routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
         routes.MapRoute(
             "Default", // Route name
             "{controller}/{action}/{id}", // URL with parameters
             new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
         );
    
      }
    

    而且我知道这是在运行,因为我可以断点它。

    <小时/> 眼镜: Windows 7 | Visual Studio 2010/2012 | Microsoft MVC3 | IIS Express


    我已经阅读了所有这些SO帖子,似乎没有适用于这种情况或者没有帮助(主要是因为它们适用于实际的aspx页面,我试图通过控制器加载页面):

    The HTTP verb POST used to access path '/' is not allowed

    The HTTP verb POST used to access path is not allowed

    The HTTP verb POST used to access path '/Membership/user/' is not allowed

    The HTTP verb POST used to access path '/Main/[object Object]' is not allowed

    The HTTP verb POST used to access path '[my path]' is not allowed

    HTTP verb POST used to access path '/' is not allowed in Facebook app


    有什么想法吗?

1 个答案:

答案 0 :(得分:0)

问题出在这里(由于我缺乏MVC / CSHTML经验):

<form id="ScriptForm" action="/MyApp/ControllerName/ActionName/@ViewBag.IDNumber" method="post">
...
</form>

MyApp曾经在我的电脑上工作(老实说,我不确定为什么它现在不起作用......也许我之前为这个名字做了一些事情要解决?)但它不再映射到任何东西。它可以在服务器上运行,但那是因为在IIS中确实存在“MyApp”的映射。只需将此表单更改为:

<form id="ScriptForm" action="@Url.Content("~/ControllerName/ActionName/" + ViewBag.IDNumber)" method="post">
...
</form>

......工作更优雅,没有错误。