Monday, 16 June 2014

System.Security.SecurityException: Request for the permission of type ‘System.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ failed


Error in web service
Ans)Add in the web.config, under system.web section:
Securing Web Services
We can provide the security in different ways
you can pass “UserName” and “password” as Parameter while calling “WebService”,
then you can use “Custom Logic”
or “imparative security”
or “declarative security” to authenticate Users
Using PrincipalPermission attribute
[WebMethod]
//Restrict web method access to users in admin role alone.
[System.Security.Permissions.PrincipalPermission
(System.Security.Permissions.SecurityAction.Demand, Role="Admin")]
public string HelloWorld()
{
//Your code
}
[WebMethod]
//Restrict web method access to a particular user
[System.Security.Permissions.PrincipalPermission
(System.Security.Permissions.SecurityAction.Demand, Name="SoSO")]
public string HelloWorld1()
{
//Your code
}