我的asp.net课程中没有调用自定义的Authorization属性,我无法告诉我缺少的内容。
我的属性如下所示:
[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;
}
}
我在WebService中调用它是这样的:
[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不存在。
答案 0 :(得分:3)
你似乎在ASP.NET Web API和传统的经典ASMX WebServices之间制造了一个可怕的混淆。您编写了一个ASP.NET Web API授权属性(旨在用于ASP.NET API REST服务)并将其应用于旧版ASMX WebService。这两种技术完全不同,不应混合在一起。
这就像试图将兰博基尼发动机放在马车上一样。