1

I have searched but no solutions seem to work for me. I have a web forms VS2013 solution and I've been adding MVC to this using an Area. I have got everything working when I specify e.g.: http://localhost:51961/MVC/contractfiles/index/

This works fine, but I need it to go to the same page when i use:

http://localhost:51961/MVC/contractfiles/

instead I get HTTP Error 403.14 - Forbidden - The Web server is configured to not list the contents of this directory.

My Area registration is:

    namespace PublicHealthCMS_L3.Areas.MVC
    {
        public class MVCAreaRegistration : AreaRegistration 
        {
            public override string AreaName 
            {
                get 
                {
                    return "MVC";
                }
            }

            public override void RegisterArea(AreaRegistrationContext context) 
            {
                context.MapRoute(
                    "MVC_default",
                    "MVC/{controller}/{action}/{id}",
                    new { action = "Index", id = UrlParameter.Optional },
                    namespaces: new[] {"PublicHealthCMS_L3.Areas.MVC.Controllers" }
                );
            }
        }
    }

And my contractfiles controller:

namespace PublicHealthCMS_L3.Areas.MVC.Controllers
{
    public class ContractFilesController : Controller
    {
        private PublicHealthCMSEntitiesMVC db = new PublicHealthCMSEntitiesMVC();

        // GET: MVC/ContractFiles
        public ActionResult Index()
        {
            int ContractID = MySession.Current.ContractID;
            return View(db.pr_File_Select(242).ToList());
        }

Thanks for any help

Main route:

namespace PublicHealthCMS_L3
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "contractfiles", action = "Index", id = UrlParameter.Optional },
                namespaces: new string[] { "PublicHealthCMS_L3.Controllers" }
            );

            //.DataTokens = new RouteValueDictionary(new { area = "MVC" } );

        }
    }
}

Global.asax Application_Start

void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup     
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            RouteConfig.RegisterRoutes(RouteTable.Routes);            


            //RegisterRoutes(RouteTable.Routes);

        }

I also have some webapi routes, WebApiConfig.cs:

namespace PublicHealthCMS_L3
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }
}

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=169433
  -->
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="PublicHealthCMS_L3.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
    <!-- 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" />
  <section name="glimpse" type="Glimpse.Core.Configuration.Section, Glimpse.Core" /></configSections>
  <appSettings>
    <add key="RouteDebugger:Enabled" value="false"/>
    <add key="MessageNoContractSelected" value="No contract is selected, please click Search and select a contract" />
    <add key="MessageDeleteRecordFilesExist" value="This record has associated files, please expand the record and remove the files first before the record can be deleted" />
    <add key="Version" value="1.02" />
  <add key="RouteDebugger:Enabled" value="true" /></appSettings>
  <connectionStrings>   
    <add name="PublicHealthCMSConnectionString" connectionString="Data Source=bcvPHDEVSQL;User Id=PublicHealth_User; Password=;Initial Catalog=PublicHealthCMS;" providerName="System.Data.SqlClient" />
    <add name="PublicHealthCMSEntities" connectionString="metadata=res://*/CRMModel.csdl|res://*/CRMModel.ssdl|res://*/CRMModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=BCVPHDEVSQL;initial catalog=PublicHealthCMS;User Id=PublicHealth_User; Password=;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    <add name="PublicHealthCMSEntitiesMVC" connectionString="metadata=res://*/Areas.MVC.Models.CMSModel.csdl|res://*/Areas.MVC.Models.CMSModel.ssdl|res://*/Areas.MVC.Models.CMSModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=bcvPHDEVSQL;initial catalog=PublicHealthCMS;user id=PublicHealth_User;password=;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

  <system.web>
    <httpRuntime maxRequestLength="20480" />
    <httpHandlers>
      <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false" />
    <add path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" /></httpHandlers>
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <!--<add assembly="System.Data.Entity, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />-->
        <add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
      </assemblies>
      <buildProviders>
        <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </buildProviders>
    </compilation>
    <authentication mode="Windows">
    </authentication>
    <authorization>
      <deny users="?" />
      <!-- This denies access to the Anonymous/unregistered user -->
      <allow users="*" />
      <!-- This allows access to all registered users -->
    </authorization>
    <identity impersonate="false" />

    <pages controlRenderingCompatibilityVersion="4.0"></pages>
  <!-- Glimpse: This can be commented in to add additional data to the Trace tab when using WebForms
        <trace writeToDiagnosticsTrace="true" enabled="true" pageOutput="false"/> --><httpModules>
            <add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" />
        </httpModules></system.web>
  <system.webServer>

    <!--<directoryBrowse enabled="true" />-->
    <modules runAllManagedModulesForAllRequests="true"><add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" preCondition="integratedMode" /></modules>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />



      <!-- Your other remove tags-->
      <!--
      <remove name="UrlRoutingModule-4.0" />
       -->
      <!--Your other add tags-->
      <!--
      <add name="UrlRoutingModule-4.0" path="*" verb="*" type="System.Web.Routing.UrlRoutingModule" preCondition="" />-->
    <add name="Glimpse" path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" preCondition="integratedMode" /></handlers>
    <defaultDocument>
      <files>
        <!--<add value="Search.aspx" />-->
        <add value="Index.cshtml" />
      </files>
    </defaultDocument>
  </system.webServer>
  <system.serviceModel>
    <bindings />
    <client />
  </system.serviceModel>
  <applicationSettings>
    <PublicHealthCMS_L3.Properties.Settings>
      <setting name="PublicHealthCMS_L3_ActiveDirectory_ActiveDirectory" serializeAs="String">
        <value>http://bcvmbiis02/tools/ActiveDirectory.asmx</value>
      </setting>
    </PublicHealthCMS_L3.Properties.Settings>
  </applicationSettings>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <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.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
      <!-- 
          For more information on how to configure Glimpse, please visit http://getglimpse.com/Help/Configuration
          or access {your site}/Glimpse.axd for even more details and a Configuration Tool to support you. 
      -->
    </glimpse></configuration>

Also, the web.config within the MVC area:

<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="PublicHealthCMS_L3" />

      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <!--<add key="webpages:Enabled" value="false" />-->
  </appSettings>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
</configuration>

3 Answers 3

1

Replace this

new { action = "Index", id = UrlParameter.Optional }

with this:

new { controller="ContractFiles", action = "Index", id = UrlParameter.Optional }

And try to rebuild the project. I just verified - and it works

Sign up to request clarification or add additional context in comments.

6 Comments

Show your app route registration please
I've updated question to include Applicaiton_Start method of Global.asax and standard RouteConfig. Is that what you mean?
what is in RouteConfig.RegisterRoutes(RouteTable.Routes)?
try to rebuild the project. I just verified - and it works
Tried rebuilding and same error. The are 4 items within the RouteTable.Routes collection, I think it includes my webapi routes too, could it be something to do with these? I've included my WebApiConfig.cs? Many thanks
|
0

Try to add it in WebConfig file:

 <system.webServer>
   <modules runAllManagedModulesForAllRequests="true"/> 
 </system.webServer>

and

    <system.webServer>
      <defaultDocument>
       <files>
      <add value="index.cshtml" />
      </files>
     </defaultDocument>
    <directoryBrowse enabled="true" />
    </system.webServer>

Please see the answer from "IIS not running ASP.NET MVC application"

4 Comments

Thanks, I already tried this but the error shows when it is not running from the web server but from local dev PC,
HTTP Error 403.14 - Forbidden - The Web server is configured to not list the contents of this directory. It basically doesn't recognize the URL without Index. If I add index then it works fine.
@Blingers Did youi add defaultDocument in WebConfig?
Yes tried that and still the same error. I've added my web.config to the question if that helps. Thanks
0

This was a strange error and I've 'resolved' it by adding a new controller and copying and pasting everything from the existing controller into this new one. The new one works fine. Very irritating that I've spent 3-4 days trying to solve a problem that is obviously some sort of bug as the new controller is exactly the same as the existing one but works fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.