What do you mean by "Unsafe" ?
Do you mean the code that should be protected with role-based security ?
If so - yes this is possible, - for example consider the following webservice that returns some string about status of the user:
[WebMethod]
public string IsAuthenticated()
{
if (User.Identity.IsAuthenticated)
{
// you can also use User.Identity.Name
string userName = System.Web.Security.Membership.GetUser().UserName;
string[] roles = System.Web.Security.Roles.GetRolesForUser(userName); string allRoles = "";
foreach(string role in roles)
allRoles = String.Concat(allRoles, ", ", role);
return String.Format(
"Yes, user is authenticated, username: {0}; roles:{1}",
userName,
allRoles
);
}
else
return "No - user is not authenticated";
}
PS. I think I misunderstood the question - there is actually a detailed description of "unsafe" code for .NET, so I am sorry :)
anyway I am not deleting the text above.