0

I have a asp.net mvc4 webapp that has a Default.aspx in the root (not Views/Home...etc). When I publish it to the hosting provider via ftp and type the domain () in the web browser it says:
Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: /

I've tried it even with Default.aspx and Index.aspx. If I type the domain with the page name (domain/Default.aspx) it works fine.

My 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>
  <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>
    <defaultDocument enabled="true">
      <files>
        <clear />
        <add value="index.aspx" />
      </files>
    </defaultDocument>
    <modules runAllManagedModulesForAllRequests="true" />
    <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>

I need to achive that the page loads when only the domain is typed. It can either redirect me to domain/Default.aspx or just stay like that (domain) and show the site.

The provider says they run IIS 7.5 and Default.aspx and Index.aspx should be fine too for them.

If you need anything else, let me know.

Thanks in advance, davegen

1 Answer 1

1

You should do this with a controller, not a static aspx page. By default in MVC, if you make a HomeController, with an Index action, it will render the returned view when the user doesn't specify a controller/view.

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

If you don't want to call it HomeController, you can change the default in App_Start/RouteConfig.cs

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Default", action = "Index", id = UrlParameter.Optional }
);
Sign up to request clarification or add additional context in comments.

7 Comments

I've have tried the RouteConfig earlier, but didnt work. I did the 'HomeController' but if it could, it went worse. Now the error is the following: The view at '~/Default.aspx' must derive from ViewPage, ViewPage<TModel>, ViewUserControl, or ViewUserControl<TModel>. Any idea?
Does Default.aspx have any C# code in it, or is it just plain HTML?
I just created this for a test, everything is default. Created a Web Form, and put some text in the div inside it. Nothing else got modified. I mean of course i created the homecontroller etc but nothing difficult that could mess things up.
I wasn't sure, so I tested it with a quick project. You can't use a WebForm (.aspx) as an MVC view page. In your HomeController, you should just have return View(); Once you have that, right click on it, and click "Add view". Visual studio will then put Index.cshtml into ~/Views/Home. Try that and you should be all set
Seems like it did the trick! I added a little piece of code: Server.Transfer("Index.aspx"); so the cshtml redirects to the goal. Is it a good solution for this?
|

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.