2014-10-18 81 views
2

我有這個問題,即如果我叫URL這樣MVC 5 HTTP錯誤403.14 - 禁止

http://localhost:5330/Admin/ 

它拋出我

HTTP Error 403.14 - Forbidden 

同時也讓喜歡這工作得很好

http://localhost:5330/Admin/Index 

Web.config:

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    http://go.microsoft.com/fwlink/?LinkId=301880 
--> 
<configuration> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 

    <system.web> 
    <authentication mode="None" /> 
    <compilation debug="true" targetFramework="4.5.1" /> 
    <globalization uiCulture="es-US" culture="es-US"></globalization> 
    <httpRuntime targetFramework="4.5.1" /> 
    <pages> 
     <namespaces> 
     <add namespace="Kendo.Mvc.UI" /> 
     </namespaces> 
    </pages> 
    </system.web> 
    <system.webServer> 
    <handlers> 
     <!--register windows login managed handler.--> 
     <add name="Windows Login Handler" path="Login" type="CSP.Web.WindowsLoginHandler" verb="GET,POST" preCondition="integratedMode" /> 
    </handlers> 
    <modules> 
     <remove name="FormsAuthenticationModule" /> 
    </modules> 
    </system.webServer> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Http" publicKeyToken="31BF3856AD364E35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 

    <system.web.extensions> 
    <scripting> 
     <webServices> 
     <jsonSerialization maxJsonLength="500000000" /> 
     </webServices> 
    </scripting> 
    </system.web.extensions> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 

    <system.data> 
    <DbProviderFactories> 
     <remove invariant="System.Data.SqlClient.4.0" /> 
     <add name="Microsoft SQL Server Provider 4.0" invariant="System.Data.SqlClient.4.0" description=".NET Framework Data Provider for Microsoft SQL Server" type="System.Data.SqlClient.SqlProviderFactory, System.Data.SqlClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" /> 
    </DbProviderFactories> 
    </system.data> 
</configuration> 

的Global.asax.cs:

using CSP.Web.Models; 
using System; 
using System.Collections.Generic; 
using System.Data.Entity; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using System.Web.Optimization; 
using System.Web.Routing; 

namespace CSP.Web 
{ 
    public class MvcApplication : System.Web.HttpApplication 
    { 
     public MvcApplication() 
     { 
      this.RegisterWindowsAuthentication(); 
     } 
     protected void Application_Start() 
     { 

      Database.SetInitializer<ApplicationDbContext>(null); 
      FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 
      RouteConfig.RegisterRoutes(RouteTable.Routes); 
      BundleConfig.RegisterBundles(BundleTable.Bundles); 
     } 
     protected void Application_Error() 
     { 

      HttpContext ctx = HttpContext.Current; 

      System.Exception exe = ctx.Server.GetLastError(); 
      //if (exe.Message.Contains("undefined")) 
      //{ 
      // return; 
      //} 
      //else 
      //{ 
      KeyValuePair<string, object> error = new KeyValuePair<string, object>("ErrorMessage", ctx.Server.GetLastError().ToString()); 
      CSP.Web.Helpers.Log objLog = new CSP.Web.Helpers.Log(); 
      objLog.LogError(ctx.Server.GetLastError().ToString()); 
      ctx.Response.Clear(); 
      Response.Redirect(String.Format("/Error/{0}", "ShowError")); 
      ctx.Server.ClearError(); 
      //ctx.Response.End(); 
      //} 

     } 
    } 
} 

回答

3

這可能是正確的行爲。當您調用/ Admin /時,它會嘗試列出該文件夾的內容,這當然是IIS禁用的(默認情況下)。調用/管理/索引將帶您進入AdminControllerIndex()操作。

您的解決方案是設置默認路由,以便/ Admin /轉發到/ Admin/Index。確保你的下面幾行在你的地方Global.asax.cs

// Default MVC route (fallback) 
routes.MapRoute(
    "Default", // Route name 
    "{controller}/{action}/{id}", // URL with parameters 
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults 
); 
+0

我有他們在RouteConfig。那會好的 – Vivekh 2014-10-18 16:43:04

+0

@Vivekh應該沒問題,只要該代碼在Web應用程序啓動時運行即可... – Ruslan 2014-10-18 17:29:03

+0

是它在應用程序啓動時運行,但我面臨着同樣的錯誤 – Vivekh 2014-10-19 15:55:41