Is it possible to access Controller/Action attributes from a Message Handler? - asp.net-web-api

Is there a practical way to access the attributes decorating a controller or action from a Message Handler/ DelegatingHandler?
From the diagram on Pedro Felix's blog entry, it looks like Message Handler's are too early in the pipeline and the info won't be available until the Controller Dispatcher Message Handler runs. Correct?
About my use case:
I'm working with the Thinktecture identity model, and it would be useful to be able to look for the AllowAnonymous attribute in the AuthenticationHandler.

By nature, this seems to be the wrong place to implement it. As you have noted, Message Handlers work across all requests and responses. If you depend on an attribute, this would naturally be a filter. So I suggest you follow that route.
In fact in the handler you cannot assume there is going to an ApiController or an action. Handlers can be equally used on clients.

Related

Save data through the controller after an event has been fired in laravel

I'm allowing a user to upload a post which includes an image and some related information as well as select the promotion fee[bronze,silver or gold].In my /post controller i'm validating the request and then sending a request to another API[third party api for performing payments].The API takes the user phone number and the promotion fee selected and does the payment transaction.So i made the Transaction model[used to save details concerning the completed transaction]to dispatch a created event since i want to save the other post related information only if the payment is successful.
I've tried to create the listener for the TransactionCreatedEvent but i can't find a way to pass the post related data into the listener in order to save them. I also tried to use the closure by calling the listen method on the Event Facade inside the post controller to no avail.
Mh, i'm not quite sure if i undestood you question correctly, but in you case, you could either relate the Transaction with the post, or pass the Transaction and the Post Model to any event or to a job, and then do whatever you want with the data in the event handler or job

Glympse API event handling

I am trying to launch glympse app by using an intent and receiving the information through broadcast. Is there any way that I will be notified about the events occurring like ticket removed, expired, updated etc?
There sure is.
We created a library project to make this easier for you. It can be found here: https://github.com/Glympse/glympse-app-sdk/tree/master/Android/GlympseIntentsLib
A sign-in is required to view these documents that might be helpful.
Tutorial: https://developer.glympse.com/Content/client/app/guides/Glympse_Intents_Tutorial.html
Reference Docs: https://developer.glympse.com/Content/client/app/guides/Glympse_Intents_Reference.html
Specifically, check out the method CreateGlympseParams.setCallbackAction(String). This will allow you to set an action which will be used to broadcast a message back to your app.
Another option is to use CreateGlympseParams.setEventsListener(EventsListener). With this method, you can supply an object that implements GlympseApp.EventsListener. Using this method, our library handles the broadcast under the covers and your object's methods will be invoked as the event occur.

How the view communicate with controller in MVC?

I am trying to understand and use the MVC without a framework, until now I clearly understand what is the role of Model, View and Controller and how are they made.
But I have one question. If the Controller is a class with methods for every action in thew View, and in that method we communicate with the Model and ask some data or send some data, and then send that data to the view that we choose to display. My question is how we call that method from view when we need to send some data from view to controller?
Let say that we have a page with all users and when we click one user we want information about him and we send his id with post or get and we have a UserController with a GetUserInformation method wich communicate with model send the id receive the information set it to the view and call view() to show the information.
How do we call this method from View when the client clicks that user?
We made another file between them and send the user to that file and in that file we instantiate a controller object and call the method? But if we do that how is that file called in MVC?
And there are a lot of example, like login, add a user and so on when we need to call a method from controller and send some data or just call it without send data.
The general idea is how we call a method from a Controller object on an action in html page?
Since you have multiple php posts, I will assume that you are referring to implementing MVC or MVC-inspired architecture in context of web applications.
First of all: controllers are not responsible for passing data from the model layer (not a "model class") to the current view. The controller in MVC is only responsible for altering the state of the model layer (and in extremely rare cases - the current view's state) based on the user's input.
The second thing that you have to understand is the request-response nature of php. The instances in your application do not live past the execution of the site's code.
As for the view, its task is to create a response, which gets sent to a user. The "user" for your web application is not a human. Instead, what actually gets the response is a browser. And the browser does not get "the view". It only receives the response that was produced by the view.
Therefore:
It is not possible, in correctly implemented MVC-based web applications, for a view to call methods on the controller because:
you are not interacting with a view, but with a response
the view and controller are both already destroyed
P.S: at the beginning you wrote "until now I clearly understand what is the role of model,view and controller and how are they made", but it is clearly untrue.

MVC: Where to trigger user registration emails

I am building an MVC application (using the Zend Framework).
When users first register, the applicaiton sends them an email. My question is, where should I trigger this email from? The model or the controller? My thoughts are as follows:
In some ways, the model makes sense, since sending a registration email is part of my business logic. Users must click the link in the mail to validate their email address.
But by putting it in the model, I am 'encumbering' the model. The model's registerUser action is then only useful within the context of an application that needs emails sent for every registration.
Instead, by triggering the email from within the controller, my controller would be a litter 'fatter', but my model a little more 'fine grained'.
I have written an email service which actually configures and sends the email, and I think this is a good design decision. I am really just asking where I should be calling this service from.
Your thoughts are most appreciated!
According to Zend Framework's definition of MVC, you should put send the email from the controller:
Controllers...decide which view to display based on the user's request.
Models, on the other hand, contain:
...basic functionality behind a set of abstractions.
An email may be considered a "view" in that it displays information to the user. It is the controller's job to activate this "view."
In my opinion, I would want this in the model, as I would consider this an assumed process of the create user method, rather than any specific interaction with the user making the request.
In other words, since I would always want this email sent, regardless of the source of the request, I would identify this as a natural byproduct of the create user action, similar to a record being saved in a database.
You might want to look into using something like NServiceBus to queue messages to be sent to your Email Service.
This way you can have NServiceBus subscribe to an event that occurs and omit any manual firing of the email service etc.
Ultimately you want a failsafe way of ensuring your messages get to the intended people. This kind of framework will greatly help you ensure that this happens.
Alternatively you could store the emails to be sent inside your database and have your email service check the database queue every x minutes for new emails to send and omit the need for triggering the email sending.
Again, doing it this way will ensure at the least that the emails get sent. Should the network go down or some other disruption occur during the sending of each email you can simply leave them in the queue until the network comes back up.

Which event to handle in HttpModule for setting the current principal when dealing with providers?

I am facing a problem where I have to integrate with a custom HttpModule where the principal and identity are set on the current thread so that HttpContext.Current.User contains these. However I get the feeling that the eventhandler they used (PostAcquireRequestState) is way too late.
Which is the best event to handle before the initialization of the providers happen in the HttpModule? All I want is my custom provider to work with the correct principal and identity.
This is probably best done in the PostAuthenticateRequest event. ASP.NET assumes that after this event the security information is stable.

Resources