Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

It works for me,I hope this will help you.

using System.Web.Mvc;

public class CustomAuthorize : AuthorizeAttribute
{

}

In controller

 [CustomAuthorize]
public class OrderController : Controller
{

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top