2013-02-28 94 views
0

我是新來的,我得到一個錯誤,不知道如何解決。在2012年視覺工作室快遞錯誤

我創建了一個新的mvc4項目(c#),爲空模板。

然後我添加了一個控制器(MVC空模板),我把他的代碼:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 

namespace Testing.Controllers 
{ 
public class Testing2Controller : Controller 
    { 
    // 
    //GET: /Testing2/ 

    public string Index() 
    { 
     return "01111000100011"; 
    } 

    } 
} 

和我得到這樣的:在 '/' 應用

服務器錯誤。

無法找到該資源。

說明:HTTP 404.您正在查找的資源(或其某個依賴項)可能已被刪除,名稱已更改或暫時不可用。請檢查以下網址並確保它拼寫正確。

請求的URL:/

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.17929

我的web.config文件是這樣的:

<?xml version="1.0" encoding="utf-8"?> 

<configuration> 
    <appSettings> 
    <add key="webpages:Version" value="2.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="PreserveLoginUrl" value="true" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    </appSettings> 
    <system.web> 
    <httpRuntime targetFramework="4.5" /> 
    <compilation debug="true" targetFramework="4.5" /> 
    <pages> 
     <namespaces> 
     <add namespace="System.Web.Helpers" /> 
     <add namespace="System.Web.Mvc" /> 
     <add namespace="System.Web.Mvc.Ajax" /> 
     <add namespace="System.Web.Mvc.Html" /> 
     <add namespace="System.Web.Routing" /> 
     <add namespace="System.Web.WebPages" /> 
     </namespaces> 
    </pages> 
    </system.web> 
    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <handlers> 
     <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> 
     <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> 
     <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> 
     <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*."  verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> 
     <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> 
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 
    </handlers> 
    </system.webServer> 

</configuration> 

非常感謝你,我沒有做什麼

回答

0

你的控制器想法方法需要返回ActionResult。你需要做的是這樣的:

public ActionResult Index() 
{ 
    return Content("01111000100011"); 
} 

更新

我只是注意到錯誤中提到的URL /。要在你的問題中找到控制器操作,你必須去/Testing2

+0

謝謝,但沒有幫助 – 2013-03-01 00:02:01

+0

你有沒有配置任何路由? – 2013-03-01 00:12:37

+0

我有這樣的: 命名空間測試 { 公共類RouteConfig { 公共靜態無效的RegisterRoutes(RouteCollection路線) { routes.IgnoreRoute( 「{}資源個.axd/{*} PATHINFO」); routes.MapRoute( 名稱: 「默認」, 網址: 「{控制器}/{行動}/{ID}」, 默認:新{控制器= 「家」,行動= 「指數」,ID = UrlParameter .Optional} ); } } } – 2013-03-01 01:01:13