I run an Azure web role in Full IIS mode. Requests are authorized with custom basic authentication.
I have MyAssembly.CustomIdentity
class that inherits from System.Security.Principal.GenericIdentity
. When HttpApplication.AuthenticateRequest
handler (OnEnter()
code from the link above) is invoked it performs checks, then creates an instance of MyIdentity.CustomIdentity
and assigns it to HttpContext.Current.User
. Then an actual ASP.NET request handler obtains that object and can use it to find what user it is for.
Now everything more or less works fine in default configuration when IIS is running under NETWORK SERVICE
account. During role startup I restart IIS application pool under a local user (to grant it extra privileges). Now even the following code
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
bool isAvailable = Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.IsAvailable;
}
}
will throw various exceptions. First it says it can't serialize my CustomIdentity
class (which I fix by adding Serializable
attribute), then it says it can't load MyAssembly
assembly (which I fix by handling AppDomain.AssemblyResolve
event).
What I don't get is why serialization kicks in? Why running the application pool under s local user and invoking that trivial code suddenly trigger serialization?