1

I'm currently using MVC4.

  • I have a folder in my project that has files (images, doc and pdf files).
  • I have a database with a list of users (.net membership guids) that have permission to access each of the files.

What I'm currently researching and I'm asking you advice, as I never did it on MVC:

Any tip regarding how to catch the http request of the file and then decide on runtime if the user has permissions to acces or not? Is there any kind of http handler that let me do that on MVC? Any other idea or tip?

Thanks in advance!..

PnP

2
  • how would this be different than webforms? Commented Nov 13, 2012 at 19:07
  • I don't know... I assumed that MVC may give me some new ways of doing this (or optimal ways) that I'm not aware of. That's why I made the post Commented Nov 13, 2012 at 19:09

1 Answer 1

1

I would create a new FileAuthorizeAttribute and decorate a new controller method.

public class FileAuthorizeAttribute: AuthorizeAttribute
{
    protected override bool IsAuthorized(HttpActionContext actionContext)
    {
        if (base.IsAuthorized(actionContext))
        {
            // check if guid is in your database
        }

        return false;
    }

    public override void OnAuthorization(HttpActionContext actionContext)
    {
        base.OnAuthorization(actionContext);
    }
}

public class FileController : Controller
{
    [FileAuthorize]
    public FileResult Load(string fileName)
    {
        //return File(fileName, contentType);
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

I'll try that!.. sounds exactly like what I'm looking for. So you think that the "fileName" string will bring the file that you try to access to the FileResult function? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.