I need to access a cookie encrypted in C#’s FormsAuthentication method, apparently found in System.Web.Security, using PHP. Since I flamed out in trying to port Forms.Authentication.decrypt to a PHP solution, I am turning now to using Mono to write a small console app to pass the encrypted cookie to Forms.Authentication.decrypt but I’m getting this error:
The type or namespace name
Security' does not exist in the namespaceSystem.Web’. Are you missing an assembly reference?
Here’s the code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Security.FormsAuthenticationTicket;
namespace Cookie
{
public class CookieDecrypt
{
public static void Main(string[] args)
{
if (args.Length == 0)
{
throw new System.ArgumentException("Please invoke like: mono CookieDecrypt.exe CookieString", "args");
}
string CookieValue = args[0];
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(CookieValue);
Console.WriteLine(authTicket.Expired);
}
}
}
}
I see some .dlls in /usr/lib/mono/2.0/ such as System.Security.dll but not System.Web.Security.dll, though http://docs.go-mono.com indicates it’s available (search for forms.authentication encrypt comes up with several results, including one that says FormsAuthentication Class (System.Web.Security.FormsAuthentication).
I’m compiling like this: mcs test.cs
As you are undoubtedly aware, I’m new to c# and mono (installed in a couple of hours ago). Can anyone help me understand what is happening and how I can fix it?
FormsAuthenticationTicket is a class.
usingstatements are for namespaces only. The namespace you want is System.Web.Security. FormsAuthenticationTicket is located in the System.Web.dll assembly, however.The .NET documentation is actually quite explicit about which namespaces and which assemblies classes are in. Example: http://msdn.microsoft.com/en-us/library/system.web.security.formsauthenticationticket.aspx
As you can see, just under the Inheritance Hierarchy are both the assembly and namespace.