0

我需要使用 PHP 访问在 C# 的 FormsAuthentication 方法中加密的 cookie,显然是在 System.Web.Security 中找到的。由于我在尝试将 Forms.Authentication.decrypt 移植到 PHP 解决方案时失败了,我现在转而使用 Mono 编写一个小型控制台应用程序来将加密的 cookie 传递给 Forms.Authentication.decrypt 但我收到了这个错误:

类型或命名空间名称Security' does not exist in the namespace System.Web'。您是否缺少程序集参考?

这是代码:

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);
        }
    }
}

}

我在/usr/lib/mono/2.0/中看到了一些 .dll,例如System.Security.dll,但没有看到 System.Web.Security.dll,尽管http://docs.go-mono.com表明它可用(搜索forms.authentication encrypt 产生了几个结果,包括一个说FormsAuthentication Class (System.Web.Security.FormsAuthentication)的结果。

我是这样编译的:mcs test.cs

正如您无疑知道的那样,我是 c# 和 mono(几个小时前安装)的新手。谁能帮助我了解正在发生的事情以及如何解决它?

4

1 回答 1

1

FormsAuthenticationTicket 是一个类。using语句仅适用于命名空间。您想要的命名空间是 System.Web.Security。但是,FormsAuthenticationTicket 位于 System.Web.dll 程序集中。

.NET 文档实际上非常明确地说明了哪些名称空间和哪些程序集类在其中。示例:http: //msdn.microsoft.com/en-us/library/system.web.security.formsauthenticationticket.aspx

如您所见,在继承层次结构下是程序集和命名空间。

于 2013-01-16T18:47:15.603 回答