2
votes

I'm beginner in asp.net i just create a empty web-application and after that i create a controller but it is showing the error.

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: /

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3056.0

here is my code

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

namespace WebApplication1.Controllers
{
    public class Welcome : Controller
    {
        // GET: Welcome

        public string Index()
        {
            return "Hello World, this is ASP.Net MVC Tutorials";
        }
    }
}
3
Default controller is home and action index. So you won't have a page unless you have home controller with an indexGraemeMiller
Can you post your route config?SBFrancies

3 Answers

1
votes

You either need to rename your Welcome-Class to HomeController or change the default route in your App_Start/RouteConfig.cs to point to Welcome by default:

 routes.MapRoute(
          name: "Default",
          url: "{controller}/{action}/{id}",
          defaults: new { controller = "Welcome", action = "Index", id = UrlParameter.Optional }
      );

As a side note, you should name your controller "WelcomeController", not "Welcome".

1
votes

I recommend attribute routing. https://blogs.msdn.microsoft.com/webdev/2013/10/17/attribute-routing-in-asp-net-mvc-5/

[Route(“api/welcome”)]

Can be added to your actions to specify the route with the action.

0
votes

Either you make a change of the default controller from 'Home' to 'Welcome' in your route like this:

 routes.MapRoute(
      name: "Default",
      url: "{controller}/{action}/{id}",
      defaults: new { controller = "Welcome", action = "Index", id = UrlParameter.Optional }
  );

Or your can simply go to the following url in your browser:

http://localhost:58470/Welcome

Change the port from 58470 to your application one.