Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在ASP.NET中获取自定义授权属性中的引用人数据_C#_Asp.net_Custom Attributes - Fatal编程技术网

C# 如何在ASP.NET中获取自定义授权属性中的引用人数据

C# 如何在ASP.NET中获取自定义授权属性中的引用人数据,c#,asp.net,custom-attributes,C#,Asp.net,Custom Attributes,如何在ASP.NET中的自定义授权属性中获取引用者数据,如IP地址和apiKey。 在下面的代码中,我希望获得上述数据: [AttributeUsage(AttributeTargets.Method)] public class Auth : AuthorizeAttribute { protected override bool IsAuthorized(HttpActionContext actionContext) { var cnt = HttpCo

如何在ASP.NET中的自定义授权属性中获取引用者数据,如IP地址和apiKey。 在下面的代码中,我希望获得上述数据:

  [AttributeUsage(AttributeTargets.Method)]
public class Auth : AuthorizeAttribute
{
    protected override bool IsAuthorized(HttpActionContext actionContext)
    {
        var cnt = HttpContext.Current;
        return false;
    }
}
在HttpContext.Current中,我可以获得url引用者,但它没有我需要的所有数据

如果这个问题不清楚或不完整,请告诉我

更新: 对于那些需要知道的人,下面的代码显示了如何

[AttributeUsage(AttributeTargets.Method)]
public class Auth : AuthorizeAttribute
{

    protected override bool IsAuthorized(HttpActionContext actionContext)
    {
        var cnt = HttpContext.Current;
        int id = Int32.Parse(cnt.Request.Params["id"]);
        string apiKey = cnt.Request.Params["apiKey"];
        string IP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
        return true;
    }
}