-1

I've just started working with asp.net mvc 4. I've created this simple controller class and did this small coding but when i run my project it throw an error. I don't know what this error is and how to fix it. please help me with it.

public class HomeController : Controller 
{
    public string Index()
    {
        return typeof(Controller).Assembly.GetName().Version.ToString();
    }
}

when i run the application on google chrome it throw the follwoing error

Server Error in '/' Application.

Specified argument was out of the range of valid values. Parameter name: site

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: site

Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: site]

System.Web.HttpRuntime.HostingInit(HostingEnvironmentFlags hostingFlags, PolicyLevel policyLevel, Exception appDomainCreationException) +303

[HttpException (0x80004005): Specified argument was out of the range of valid values.> Parameter name: site]

System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9951956 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34248**

Nkosi
  • 235,767
  • 35
  • 427
  • 472

2 Answers2

2

This Should Solved the problem

go

  • Control Panel
  • Programs and Features
  • Turn Windows Features on or off
  • tick Internet Information Services
  • then Restart your Laptop

It worked for me

I found that answer here

Community
  • 1
  • 1
Victor.Uduak
  • 2,734
  • 2
  • 18
  • 24
  • 1
    This should be a comment, not an answer. If it is a duplicate question, [vote to close](http://stackoverflow.com/help/privileges/close-questions) as such and/or leave a comment once you [earn](http://meta.stackexchange.com/questions/146472/what-is-the-best-way-to-increase-my-reputation-and-privileges) enough [reputation](http://stackoverflow.com/help/whats-reputation). – Maximilian Ast Aug 19 '16 at 10:34
  • i that case, other programmers with similar problems would have to wait till i get enough reputation? good – Victor.Uduak Aug 19 '16 at 13:08
0

Problem with your Action signature. Since, the Index is a default action defined in RegisterRoutes so it would be invoked as soon as you launch the site. Since MVC excepts the return type of ActionResult and throws exception if does not find in invoked action. You can change the return type to ActionResult and wrap the return value in Json if the value return is excepted of type string.

public ActionResult Index()
    {
        return this.Json(typeof(Controller).Assembly.GetName().Version.ToString());
    }
user1672994
  • 10,509
  • 1
  • 19
  • 32