.net MVC 的 AuthorizeAttribute 扩展...两个问题
我的第一个问题是,我应该把这个自定义扩展放在哪里,以便可以调用它而不是默认的 AuthorizeAttribute?
我目前创建了一个新项目,其中包含 MVC 解决方案中的所有业务逻辑。我的逻辑项目中有一个 .cs 文件,其中包含所有安全类。我尝试向该文件添加一个扩展类,并在我的控制器上,它看到该类很好,当我添加属性时,智能感知不会对我咆哮,但是当我尝试编译时,我收到一个错误,指出类型或命名空间找不到。自定义属性是否需要放置在特殊的地方才能编译?
第二个问题...可能与第一个问题相关:当我尝试从 AuthorizeAttribute 重写 AuthorizeCore 方法时,我将 System.Web.HttpContextBase 作为 httpcontext 传递。由于某种原因,Visual Studio 无法解析 System.Web.HttpContextBase。同样,这可能与我在解决方案中保存此类的位置有关。或者也许我需要在某个地方导入一个 dll 来扩展它?
请指教。
my first question is, where do I put this custom extension so that it can be called rather than the default AuthorizeAttribute?
I currently have created a new project that contains all of my business logic within my MVC solution. I have a .cs file within my logic project that contains all of my security classes. I tried adding an extension class to that file and on my controller, it sees the class just fine and intellisense isn't barking at me when I add the attribute, but when I try to compile, I get an error that the type or namespace could not be found. Does the custom attribute need to be housed somewhere special in order to compile?
Second question...could be related to the first: When I'm trying to override the AuthorizeCore method from AuthorizeAttribute, I'm passing in System.Web.HttpContextBase as httpcontext. For some reason visual studio can't resolve System.Web.HttpContextBase. Again this might be related to where I have this class saved in my solution. Or perhaps I need to import a dll somewhere to extend this?
Please advise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,只要您在网站中正确引用了该项目,该类就可以位于任何类库项目中。您可能想尝试重新编译该项目——听起来好像能够找到源文件,但代码不在 DLL 中。
您可能需要将对 System.Web.Abstractions 的引用添加到您的项目中。虽然“基”类位于 System.Web 命名空间中,但它们位于不同的 DLL 中。
As far as I am aware the class can be in any class library project as long as you have properly referenced the project in your web site. You might want to try recompiling the project -- it sounds like it's able to find the source files, but the code isn't in the DLL.
You probably need to add in a reference to System.Web.Abstractions to your project. While the "base" classes are in the System.Web namespace, they are found in a different DLL.
它对我有用,我希望这对你有帮助。
It works for me,I hope this will help you.