asp.net mvc 4 - MVC 4 || identity || How To Disable Form Submitting For an Unauthorized User? -
I have a web app based on 'MVC4 and I have a form that is for sending (one action) By posting the server), the server now enables only the authorized approach to work with authorized users.
My problem is that I put [authorize]
before the post action in the controller so that the file was uploaded to the first server and the message to the unauthorized user to log in (Redirect the user to the register / login page).
If I am unauthorized user, then I want to stop uploading files, then I need to check that the user is an authorized user and then submit the form.
Any ideas how can I do this?
Will be affected so that the authoritative attribute
and such other features will be evaluated only after proper action. In fact this is not a feature of MVC as it is a feature of web architecture in general.
The file upload is similar to any other POST
version, on which it has been sent as part of the request Now, you have an asynchronous (AZ) file upload control Maybe, but in this case file upload is still another plain-old request.
MVC does not have to choose what your client decides to send it a big request or a small request or any request. MVC can only respond to requests made by your customer.
There is no doubt that your POST
action must be preceded by your [authorized]
. But to prevent users from spending time in uploading a file, should only be dismissed on POST
, you should do anything in UP that prevent users from making or making such requests easily Give it when they are not authenticated.
In other words, you need to program the client to work with the server to determine whether to encourage the customer to upload or not.
An easy thing you can do is check it out on User.Identity.IsAuthenticated
and display the form when it is correct:
@if (User.Identity.IsAuthenticated) {// display form razor} Else {// display login razor}
You can also interfere with submitting with javascript , Which is a deep implementation but essentially something like this:
- On submission, check that the user has been authenticated (server-side call-on-fly evening
- If not certified, you can trust the customer to determine if it is appropriate or if you are appropriate.
Hope it helps.
Comments
Post a Comment