none
Configuração mediun trust em web config RRS feed

  • Pergunta

  • Boa tarde a todos,

    O servidores da Locaweb onde hospedo meu sites só aceitam agora sites que rodam e Medium Trust.

    Fiz tudo o que sabia, alterei a Webconfig de diversas formas mas o site não roda.

    O que é preciso fazer para a aplicação rodar, uso Visual Studio 2015 com C#.

    Grato

    Dirceu M. Azevedo


    Dirceu Martins de Azevedo Grupo e-usinas Piracicaba/SP MSN:dirceuazevedo@hotmail.com SKYPE: dirceu.martins.azevedo

    quarta-feira, 17 de agosto de 2016 18:59

Respostas

Todas as Respostas

  • Olá Dirceu,

    Se a sua aplicação utiliza alguma referência que exija o uso de Full Trust e a mesma seja crucial para rodar seu sistema, não vai ter jeito...terás que mudar de hospedagem (ir para um Azure por exemplo, onde funciona muito bem). Caso esteja usando um Report Viewer (que também exija Full Trust) mas que não é crucial para rodar o sistema, aí só a geração de relatórios será prejudicada.

    Tive o mesmo problema que você, procurei alternativas (as mais inusitadas possíveis) e nada. Migrei todos os meus serviços para o Azure e não tive mais problemas.

    Espero ter ajudado. Valeu!


    Se a resposta for relevante ou tenha resolvido seu problema, marque como útil/resposta!

    André Secco
    Microsoft MSP & MSDN Tech Advisor
    Blog: http://andresecco.com.br
    GitHub: http://github.com/andreluizsecco
    Twitter: @andre_secco

    quarta-feira, 17 de agosto de 2016 19:10
  • Olá,

    Não tem nada de mais, é um portal simples coma acesso a uma base de dados SQL SERVER para leitura e gravação.

    Pode rodar sem problemas em Medium Trust, só não estou conseguindo configurar aplicação para rodar desta forma.

    Dirceu Azevedo


    Dirceu Martins de Azevedo Grupo e-usinas Piracicaba/SP MSN:dirceuazevedo@hotmail.com SKYPE: dirceu.martins.azevedo

    quinta-feira, 18 de agosto de 2016 11:40
  • Aí é que está Dirceu, se é uma aplicação normal, etc, não precisa de nenhuma configuração para rodar. Poste o erro para ser analisado.

    No Web.Config, coloca a seguinte configuração (apenas para o erro ser mais detalhado, depois você retira):

    <configuration>
        <system.web>
            <customErrors mode="Off"/>
        </system.web>
    </configuration>



    Se a resposta for relevante ou tenha resolvido seu problema, marque como útil/resposta!

    André Secco
    Microsoft MSP & MSDN Tech Advisor
    Blog: http://andresecco.com.br
    GitHub: http://github.com/andreluizsecco
    Twitter: @andre_secco



    quinta-feira, 18 de agosto de 2016 11:42
  • Olá André,

    Este é o erro apresentado:

    Server Error in '/' Application.

    Security Exception

    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 failed.

    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:
    [SecurityException: Request failed.]
       System.Security.CodeAccessSecurityEngine.ThrowSecurityException(RuntimeAssembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed) +165
       System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed) +100
       System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandleInternal rmh, Object assemblyOrString, SecurityAction action, Boolean throwException) +284
       System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack cs, PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandleInternal rmh, RuntimeAssembly asm, SecurityAction action) +70
       System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
       System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) +70
       System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +40
       System.Type.GetType(String typeName) +30
       System.CodeDom.Compiler.CompilerInfo.get_IsCodeDomProviderTypeValid() +12
       System.Web.Compilation.CompilationUtil.GetRecompilationHash(CompilationSection ps) +2175
       System.Web.Configuration.CompilationSection.get_RecompilationHash() +96
       System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDateInternal(Int64 cachedHash) +458
       System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDate(Int64 cachedHash) +51
       System.Web.Compilation.BuildManager.ExecutePreAppStart() +135
       System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +531
    

    Sds,

    Dirceu Azevedo


    Dirceu Martins de Azevedo Grupo e-usinas Piracicaba/SP MSN:dirceuazevedo@hotmail.com SKYPE: dirceu.martins.azevedo

    quinta-feira, 18 de agosto de 2016 18:59
  • Dirceu,

    1) Já tentou adicionar a seguinte configuração na seção system.web do web.config?

    <trust level="Medium" originUrl="" />

    2) Você utiliza algo da referência System.IO?


    Se a resposta for relevante ou tenha resolvido seu problema, marque como útil/resposta!

    André Secco
    Microsoft MSP & MSDN Tech Advisor
    Blog: http://andresecco.com.br
    GitHub: http://github.com/andreluizsecco
    Twitter: @andre_secco


    quinta-feira, 18 de agosto de 2016 20:00
  • Olá,

    Implementei o que me disse, ele bloqueia outra coisa.

    Server Error in '/' Application.

    Configuration Error

    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

    Parser Error Message: This configuration section cannot be used at this path.  This happens when the site administrator has locked access to this section using <location allowOverride="false"> from an inherited configuration file.

    Source Error: 
    An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

    Source File: \\windows-pd-0001.fs.locaweb.com.br\WNFS-0001\e-usinas1\web\web.config    Line: 68  (Linha da web config, onde foi implementada.)




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

    Sds.

    Dirceu Azevedo


    Dirceu Martins de Azevedo Grupo e-usinas Piracicaba/SP MSN:dirceuazevedo@hotmail.com SKYPE: dirceu.martins.azevedo

    quinta-feira, 18 de agosto de 2016 23:22
  • Posta ai todo seu Web.config (retire senhas se houver)

    Se a resposta for relevante ou tenha resolvido seu problema, marque como útil/resposta!

    André Secco
    Microsoft MSP & MSDN Tech Advisor
    Blog: http://andresecco.com.br
    GitHub: http://github.com/andreluizsecco
    Twitter: @andre_secco

    sexta-feira, 19 de agosto de 2016 01:56
  • Olá André,

    Segue toda web.config

    <?xml version="1.0" encoding="utf-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework"
          type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
          requirePermission="false"/>
      </configSections>
      <connectionStrings>
        <add name="DefaultConnection"
          connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=aspnet-e_usinas-672ddaf1-6a8c-4a3b-ac10-310795a373a8;AttachDbFilename=|DataDirectory|\aspnet-e_usinas-672ddaf1-6a8c-4a3b-ac10-310795a373a8.mdf;Integrated Security=SSPI"
          providerName="System.Data.SqlClient"/>
      </connectionStrings>
      <system.web>
        <authentication mode="None"/>
        <compilation debug="true" targetFramework="4.5.2"/>
        <httpRuntime targetFramework="4.5.2"/>
        <pages>
          <namespaces>
            <add namespace="System.Web.Optimization"/>
            <add namespace="Microsoft.AspNet.Identity"/>
          </namespaces>
          <controls>
            <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
          </controls>
        </pages>
        <membership>
          <providers>
            <!--
              ASP.NET Membership is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
            -->
            <clear/>
          </providers>
        </membership>
        <profile>
          <providers>
            <!--
              ASP.NET Membership Profile is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
            -->
            <clear/>
          </providers>
        </profile>
        <roleManager>
          <!--
                ASP.NET Membership Role is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
            -->
          <providers>
            <clear/>
          </providers>
        </roleManager>
        <!--
                If you are deploying to a cloud environment that has multiple web server instances,
                you should change session state mode from "InProc" to "Custom". In addition,
                change the connection string named "DefaultConnection" to connect to an instance
                of SQL Server (including SQL Azure and SQL  Compact) instead of to SQL Server Express.
          -->
        <sessionState mode="InProc" customProvider="DefaultSessionProvider">
          <providers>
            <add name="DefaultSessionProvider"
              type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
              connectionStringName="DefaultConnection"/>
          </providers>
        </sessionState>
        <trust level="Medium" originUrl="" />
      </system.web>
      <system.webServer>
        <modules>
          <remove name="FormsAuthentication"/>
        </modules>
      </system.webServer>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/>
            <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089"/>
            <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security.OAuth" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security.Cookies" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0"/>
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0"/>
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
        </providers>
      </entityFramework>
      <system.codedom>
        <compilers>
          <compiler language="c#;cs;csharp" extension=".cs"
            type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
          <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
            type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
        </compilers>
      </system.codedom>
      <system.web>
         <customErrors mode="Off"/>
      </system.web>
    </configuration>

    Sds,

    Dirceu M. Azevedo


    Dirceu Martins de Azevedo Grupo e-usinas Piracicaba/SP MSN:dirceuazevedo@hotmail.com SKYPE: dirceu.martins.azevedo

    sexta-feira, 19 de agosto de 2016 12:38
  • Dirceu,

    Vi pelo seu Web.config que está utilizando Identity. Ele requer Full Trust para funcionar.

    Encontrei uma thread que fala que inclusive o MVC5, Web API, etc requerem Full Trust, inclusive o Medium Trust é algo que está obsoleto.

    Veja: http://stackoverflow.com/questions/16849801/is-trying-to-develop-for-medium-trust-a-lost-cause/17218344#17218344

    Infelizmente, no seu caso, será necessário migrar a hospedagem como eu havia sugerido na primeira resposta!

    Valeu!


    Se a resposta for relevante ou tenha resolvido seu problema, marque como útil/resposta!

    André Secco
    Microsoft MSP & MSDN Tech Advisor
    Blog: http://andresecco.com.br
    GitHub: http://github.com/andreluizsecco
    Twitter: @andre_secco

    sexta-feira, 19 de agosto de 2016 13:08