'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed

Onur picture Onur · Jun 24, 2015 · Viewed 55.8k times · Source

I deployed my ASP.NET project on host but take this fail. I am trying to solve this issue for hours but could not. On my first page users enter email and password after click login button they navigate menu. All datas store in mysql db. After publish i could not see mysqldata.dll in bin folder so i have added manually.

Please help me to solve this issue. I should deploy in 2 days.

This issue is displaying after while i am trying to login.

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 for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 


[No relevant source lines]

Source File: App_Web_0twfxhxf.8.cs    Line: 0 

Stack Trace: 


[SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   MySql.Data.MySqlClient.MySqlConnection.AssertPermissions() +0
   MySql.Data.MySqlClient.MySqlConnection.Open() +190
   gop.Default.loginbutton_Click(Object sender, EventArgs e) +216
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628722
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6704
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +245
   System.Web.UI.Page.ProcessRequest() +72
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
   System.Web.UI.Page.ProcessRequest(HttpContext context) +58
   ASP.default_aspx.ProcessRequest(HttpContext context) in App_Web_0twfxhxf.8.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

This is web.config file;

<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <appSettings>

    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />

    <add key="webpages:Version" value="2.0.0.0"/>
  </appSettings>

  <connectionStrings>
    <add name="MySqlConnectionString" connectionString="Server=xxx;Database=xxx;Uid=xxx;Pwd=xxx;charset=utf8;Integrated Security=false"
   providerName="MySql.Data.MySqlClient" />
  </connectionStrings>

  <system.web>

    <customErrors mode="Off" />
    <compilation targetFramework="4.0" debug="true"/>
    <httpRuntime targetFramework="4.0" />

  </system.web>

</configuration>

I have tried to add <trust level="Medium" /> in web.config file but after that even first page can not display and give down issue.

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: D:\inetpub\xxx.com\www\web.config    Line: 24 

Answer

Andre Mendonca picture Andre Mendonca · Jun 24, 2015

Try this. Put in your Web.config.

<system.web>
 <securityPolicy>
   <trustLevel name="Full" policyFile="internal"/>
 </securityPolicy>
</system.web>

About the mysqldata.dll, go to the reference, click on mysqldata.dll, right button, properties, and check if Copy Local is set to true.

Hope it helps.