Reputation: 173
I am very new to programming in general, and to ASP.NET MVC.
I am experimenting with publishing a basic MVC project on my shared windows server ( Hostgator. I have the windows personal plan http://www.hostgator.com/windows-hosting )
The trust level of the server should be set to medium (full only for dedicated servers)
However when I created a view for my action method to return, and changed the code to " return View();" the application stops working and I get the error message:
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source Error:
Line 4: <meta charset="utf-8" /> Line 5: <meta name="viewport" content="width=device-width, initial-scale=1.0"> Line 6: <title>@ViewBag.Title - My ASP.NET Application</title> Line 7: <link href="~/Content/Site.css" rel="stylesheet" type="text/css" /> Line 8: <link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />
Does an MVC application by default need a trust level = "full" ? or is there something else I can do here? Please explain in simple terms.
To sum up, these are the working and non-working version. When I introduce the return View() things starts going to shits.
Working version:
// Controller
public class HomeController : Controller
{
public string Index()
{
return "this is working";
}
}
// View
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
Not-working version:
// Controller
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
// View
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
Upvotes: 2
Views: 4170
Reputation: 3039
Here is one reply from asp.net team. it is kind of known issue. Considering following I think, you need to contact with hosting provider.
We believe this issue is caused when the application is running in Partial Trust, as opposed to Full Trust. ASP.NET applications running on .NET 4.5 are supported only in Full Trust. You might need to talk to your hosting company to ensure that their servers are properly configured for ASP.NET 4.5 with regard to the trust level.
We were able to reproduce this issue when we lowered the trust level, and then didn't see any issues once we set the trust level back to Full Trust.
Thanks, The ASP.NET Team
Upvotes: 2
Reputation: 45490
In your web.config
:
<system.web>
<trust level="Full"/>
</system.web>
Upvotes: 3
Reputation: 525
You added return View()
which links to Views\Home\Index.cshtml in your project folder. If this file is missing, your app will generate an error.
Upvotes: 1