2

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)

  • I created an ASP.NET web application, empty MVC project.
  • I created a home controller and returned a string. So far the webpage worked.

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>

3 Answers 3

3

In your web.config :

<system.web>
    <trust level="Full"/>
</system.web>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for answer! I have tried this, but the server only allows "medium" trust level. That is why I am trying to understand if asp.net mvc requires "full" access or if it can be medium
Put <trust level="Medium"/> to the local web.config and see if it works locally. MVC does not require full trust but it might be that you use something which does not work in medium trust. Example stackoverflow.com/questions/14441877/…
2

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.

https://connect.microsoft.com/VisualStudio/feedback/details/795612/mvc5-template-project-cannot-deploy-to-hosting-service

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

Comments

1

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.

2 Comments

Thanks for answering! I understand. However the Index.cshtml file is present. It seems for some reason that once I start using this feature (returning the View, using the ViewBag object etc), the trust level becomes an issue :S
Can you show the controller code and the previous lines for the view?

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.