Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.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_Asp.net Mvc_Asmx - Fatal编程技术网

C# 未调用自定义ASP.NET属性

C# 未调用自定义ASP.NET属性,c#,asp.net,asp.net-mvc,asmx,C#,Asp.net,Asp.net Mvc,Asmx,我的asp.net类中没有调用一个自定义授权属性,我不知道缺少了什么 我的属性如下所示: [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] public class MyAuthorize : System.Web.Http.AuthorizeAttribute { public override void OnAuthorization(HttpActionContext actionContext)

我的asp.net类中没有调用一个自定义授权属性,我不知道缺少了什么

我的属性如下所示:

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class MyAuthorize : System.Web.Http.AuthorizeAttribute
{
    public override void OnAuthorization(HttpActionContext actionContext)
    {
      // ...
    }

    protected bool AuthorizeCore(HttpContextBase httpContext)
    {
        // Logic here.
        return false;
    }
}
我在一个Web服务中这样称呼它:

[WebService(Namespace = "http://something/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AccessPoint : System.Web.Services.WebService
{
    [WebMethod]
    [MyAuthorize]
    public bool SomeWebMethod(int a)
    {
        //Do stuff
        return false;
    }
}
每次我运行它时,它都会直接通过,并且永远不会触发该属性。
供参考;我使用System.Web.Http.AuthorizeAttribute是因为System.Web.Mvc.AuthorizeAttribute告诉我AuthorizeAttribute不存在。

您似乎在这里对ASP.NET Web API和传统ASMX Web服务造成了严重的混淆。您已经编写了ASP.NET Web API授权属性(设计用于ASP.NET API REST服务)并将其应用于旧版ASMX Web服务。这两种技术完全不同,不应混为一谈


这就像试图将兰博基尼引擎放在马车上。

System.Web.Http.AuthorizeAttribute仅在WebApi控制器中使用。它将在MVC和其他服务中被忽略。这里有一个XMLWeb服务,它既不是MVC也不是WebApi。有关保护旧式web服务的信息,请参阅。太棒了,这正是我需要知道的,谢谢你让我直截了当。这就像试图将兰博基尼引擎放在马车上一样。很好的类比:D@loneshark99-我不认为有人在取笑任何人,只是想说明这些技术有多么不同。