Asp.net mvc 5 MVC 5 HTTP错误403.14-禁止

Asp.net mvc 5 MVC 5 HTTP错误403.14-禁止,asp.net-mvc-5,iis-8,Asp.net Mvc 5,Iis 8,我有一个问题,如果我像这样调用url 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.N

我有一个问题,如果我像这样调用url

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();
            //}

        }
    }
}
使用CSP.Web.Models;
使用制度;
使用System.Collections.Generic;
使用System.Data.Entity;
使用System.Linq;
使用System.Web;
使用System.Web.Mvc;
使用System.Web.Optimization;
使用System.Web.Routing;
名称空间CSP.Web
{
公共类MVC应用程序:System.Web.HttpApplication
{
公共mvcapapplication()
{
this.registerWindows身份验证();
}
受保护的无效应用程序\u Start()
{
Database.SetInitializer(null);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
受保护的无效应用程序\u错误()
{
HttpContext ctx=HttpContext.Current;
System.Exception exe=ctx.Server.GetLastError();
//if(exe.Message.Contains(“未定义”))
//{
//返回;
//}
//否则
//{
KeyValuePair error=新的KeyValuePair(“ErrorMessage”,ctx.Server.GetLastError().ToString());
CSP.Web.Helpers.Log objLog=new CSP.Web.Helpers.Log();
LogError(ctx.Server.GetLastError().ToString());
ctx.Response.Clear();
重定向(String.Format(“/Error/{0}”,“ShowError”);
ctx.Server.ClearError();
//ctx.Response.End();
//}
}
}
}

这可能是正确的行为。当您调用/Admin/时,它会尝试列出该文件夹的内容,这当然是IIS禁止的(默认情况下)。调用/Admin/Index会将您带到
AdminController
Index()
操作

您的解决方案是设置默认路由,以便/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
);

我把它们放在RouteConfig里了。是吗ok@Vivekh应该没问题,只要代码在web应用程序启动时运行……是的,它在应用程序启动时运行,但我面临相同的错误。如果有一个名为Account的文件夹,但它不在控制器部分,隐藏文件夹会出现吗?@Vivekh不,它们不应该出现。对不起,我忘了你正在使用MVC5。。。你真的可以发布
App\u Start\RouteConfig.cs
?最后一个文件,我保证!