How to set up a WEB application developed in C# ASP.NET (.NET Framework) for a server configured in Medium Trust?

Asked

Viewed 35 times

0

Guys, I’m having the biggest headache to host a website, developed in C# ASP.NET (.NET Framework), MVC, on the server of LOCAWEB. Their server is set to Medium Trust and their confidence level is locked with Location allowOverride="false", i.e., I cannot simply declare trust level="Full" on the web.config application level, because it won’t have any effect. They instructed me to declare [Assembly: Allowpartiallytrustedcallers] in the application’s Assemblyinfo.Cs, but it still doesn’t work.

Well, to make it easier to identify and solve the problem, I set up Web.config (machine-level) on my local machine for Medium Trust as well, because theoretically, if I can run on the local machine I will be able to run on the Locaweb server as well. I also created a new application, test only, without including any package or reference to more than the ones already coming when we create the solution, so it is easier to isolate the problem.

Follow the settings of my application:

web config.:

<!--
  Para obter mais informações sobre como configurar seu aplicativo ASP.NET, visite
   https://go.microsoft.com/fwlink/?LinkId=301880
  -->
<configuration>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="false" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
 
  <system.web>
    <customErrors mode="Off" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Assemblyinfo.Cs

using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;

[assembly: AssemblyTitle("Teste")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Teste")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("73599ca4-c64f-4b76-9797-28e02b4f8e51")]
[assembly: AssemblyKeyFile("ChaveTeste.snk")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AllowPartiallyTrustedCallers]

Error Erro de execução da aplicação

I’ve researched the problem in several forums, but the solution they always propose is to switch to another server. I don’t think this is the best solution. I believe there is some way to configure the application to run in environment configured with Medium Trust.

I know there are similar questions to that, but I saw that in the other questions the staff did not specify everything and there is also no plausible solution. I hope that through this question someone can give me a north.

Observing: The. Net Framework version is 4.5.

Thanks in advance!

  • Why your application needs the Full level?

  • @Leandroangelo, I just can’t get it to run on Medium Trust. I tried the basic settings I saw in various tutorials and forums, but it did not help. I don’t know if you have any more complex configuration that makes the application run in Medium Trust. I imagine you have, but I don’t know how to do this.

  • What you have in the code that requires System.Runtime.InteropServices and of System.Security?

  • Honestly, I can’t say. This example I posted here was a newly created application, without adding any component, IE, all components already come together with the application as soon as we created it. I’ll do a little research to see if I can find anything.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.