logo
down
shadow

Invoking WebApi's another action in another controller via reflection ?


Invoking WebApi's another action in another controller via reflection ?

By : Selim Reza
Date : November 19 2020, 12:41 AM
To fix this issue We have many services in our system. ( integrating with a mobile company) , You better use the ActionInvoker to do that:
code :
public HttpResponseMessage AAA()
{
    var ctrlDesc = new HttpControllerDescriptor(this.Configuration, "UsersController", typeof(UsersController));
    var actionDesc = new ReflectedHttpActionDescriptor(ctrlDesc, typeof(UsersController).GetMethod("Test2"));
    var ctrlCtx = new HttpControllerContext(this.Configuration, this.Request.GetRouteData(), this.Request);

    var apiCtrl = ctrlDesc.CreateController(this.Request) as ApiController;

    apiCtrl.Request = this.Request;
    apiCtrl.Configuration = this.Configuration;
    apiCtrl.ControllerContext = ctrlCtx;

    ctrlCtx.Controller = apiCtrl;
    ctrlCtx.ControllerDescriptor = ctrlDesc;
    ctrlCtx.Request = this.Request;
    ctrlCtx.RouteData = this.Request.GetRouteData();

    var actionContext = new HttpActionContext(ctrlCtx, actionDesc);
    actionContext.ActionArguments.Add("ggg", "royi");

    var invoker = this.Configuration.Services.GetActionInvoker();

    return invoker.InvokeActionAsync(actionContext, CancellationToken.None).Result;
}


Share : facebook icon twitter icon
How do I hook invoking controller action in MVC?

How do I hook invoking controller action in MVC?


By : Zahid Mirza
Date : March 29 2020, 07:55 AM
With these it helps You can override OnException Method On your Basecontrollor.
This will be a Catch block for all exceptions in Controllor Actions. just Exetnd all your Controllors from Basecontrollor
code :
protected override void OnException(ExceptionContext filterContext)
{
}
public class BaseController : Controller
{

    protected override void OnException(ExceptionContext filterContext)
    {
        base.OnException(filterContext);
        // Handle error here
    }
}


public class TestController : BaseController
{
    public ActionResult Index()
    {
        // If any exceptions then will be caught by 
        // BaseController OnException method
    }
}
MVC3 Url.Action() not working as expected after invoking controller action using Execute

MVC3 Url.Action() not working as expected after invoking controller action using Execute


By : Gabriel Shields Gagn
Date : March 29 2020, 07:55 AM
around this issue I've found the problem. It was my mistake. I missed the case, that all routes in the system I'm currently working with, are defined as below:
code :
routes.MapRoute(
     "Default", // Route name
     "{application}/{controller}/{action}/{*id}", // URL with parameters
     new { controller = "Welcome", action = "Index", id = UrlParameter.Optional, application = UrlParameter.Optional } // Parameter defaults
            );
routeData.Values.Add("application", "MyApp");
Redirecting to action and invoking `tel:123` programmatically and `mailto:abc@def.com` by controller's action on a clien

Redirecting to action and invoking `tel:123` programmatically and `mailto:abc@def.com` by controller's action on a clien


By : Francesca Massarelli
Date : March 29 2020, 07:55 AM
This might help you When we click on link 123 the default calling application for our system will call this number. , Create a javascript file with the following code
code :
$(document).ready(function()
{
    window.location.replace("tel:123-456-789");
}
Controller specs when stubbing devise authentication are never invoking controller action

Controller specs when stubbing devise authentication are never invoking controller action


By : mubarak ali
Date : March 29 2020, 07:55 AM
This might help you I figured out the issue and honestly it was pretty stupid and my own fault :P. In my application controller there is a use_user_timezone around filter. The around filter was only added to callbacks if there was a current_user. Earlier on, for some reason, I prevented the code in the around filter from running unless Rails.env.test? == true. Obviously I didn't really have any reason for writing this code.. The problem was that I was not preventing the around_filter from running if it was the test environment, but that I was preventing the code in the filter method from running if it was the test environment. Because of this I was not yielding to any code to execute for the around filter, which was of course causing the issue with the controller action never executing.
The reason that devise was seeming to play an issue in the mix was because the around filter executing was dependent on a current_user being present. Due to this the controller flow was continuing on with no problem when no auth was occurring since there was no current_user.
My ng-click is not invoking the action in the controller

My ng-click is not invoking the action in the controller


By : Goodevening
Date : March 29 2020, 07:55 AM
hope this fix your issue I am using Asp.Net MVC and angular. I have this in my 'print-script.js'
code :
var MyApp = angular.module("MyApp", []);
MyApp.service('testService', function(){
    this.sayHello= function(text){
        return "Service says \"Hello " + text + "\"";
    };        
    this.sayGoodbye = function(text){
        return "Service says \"Goodbye " + text + "\"";
    };   
});
MyApp.factory('PrintApi', function ($http) {
return {
    AddData(qrData) {
     var urlBase = "http://localhost:56720/";
        //return $http.post(urlBase + '/AddData/AddData/', qrData);
        alert("Print-service invoked");
    }
    }
});
MyApp.controller('PrintController', function ($scope,testService, PrintApi) {

    $scope.addData = function() {
        alert("SDFS");
        var dataToAdd = {
            'Name': $scope.name,
            'Mobile': $scope.mobile
        };

        PrintApi.AddData(dataToAdd)
            .then(function(response) {
                alert(dataToAdd.Name + " - " + dataToAdd.Mobile);
            },
                function(error) {
                    alert('An error occured: ' + error.message);
                });
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<html>
<head >
    
   

    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body ng-app="MyApp" ng-controller="PrintController">
    <section id="contact">
        <div class="section-content">
            <h1 class="section-header">Testing the <span class="content-header wow fadeIn " data-wow-delay="0.2s" data-wow-duration="2s"> Printing Service</span></h1>
            <h3>Dummy text of the printing and typesetting</h3>
        </div>
        <div class="contact-section">
            <div class="container">
                <div class="col-md-6 form-line">
                    <div class="form-group">
                        <label for="inputName">Your name</label>
                        <input type="text" ng-model="name" class="form-control" id="inputName" placeholder=" Enter Name">
                    </div>

                    <div class="form-group">
                        <label for="inputMobile">Mobile No.</label>
                        <input type="text" ng-model="mobile" class="form-control" id="inputMobile" placeholder=" Enter 10-digit mobile no.">
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <label for="description"> Message</label>
                        <textarea class="form-control" id="description" placeholder="Enter Your Message"></textarea>
                    </div>
                    <div>
                        <button type="button" ng-click="addData()" class="btn btn-default submit"><i class="fa fa-paper-plane" aria-hidden="true"></i>Print QR</button>
                    </div>
                </div>
            </div>
        </div>
    </section>
</body>
</html>
Related Posts Related Posts :
  • How to use Addfields in MongoDB C# Aggregation Pipeline
  • MsTest TestCleanup method not called when an unhandled exception is thrown
  • missing last data when exporting gridview to excel
  • How to add array of objects to List in c#
  • Lambda Expression to order (sort) my list collection
  • Library for displaying music notation
  • How to compare two dictionaries in c# and get the output as True and False after validation
  • specify fields to be serialized with JSON
  • How do you obtain the content of a specific node using XmlDocument in C#?
  • How to ignore the first line in a csv file when you read the csv file in C#
  • c# - Problem calling public void from class
  • How to tell a class which objects it should create? Type vs. object confusion :(
  • Save CheckBox state to xml
  • WIX CAQuietExec NETSH Command Fails
  • Issues sending http put request every 60 seconds to RoR app
  • ConfigurationManager.ConnectionStrings.ConnectionString Issue
  • Real size WPF controls for printing
  • How to cancel properly?
  • C# String multiplication error
  • Using Solrnet and Assigning Attributes with Entity Framework Generated POCOs
  • Regex pattern for single backslash
  • TextBox: insert spaces for credit card number?
  • C# DLL loaded for exe-application is not found when launching similar DLL by rundll32.exe
  • Debug a Windows Service with WCF library
  • Open a file from an external assembly?
  • Servicestack RegistrationFeature Unable to bind request
  • Index was outside the bounds of the array confusion
  • Error in Xml to List code. The ':' character, hexadecimal value 0x3A, cannot be included in a name
  • I am trying to do a while loop with a string conditional statement in C#
  • C# 'Cannot access a disposed object. Object name: 'SslStream'.'
  • How to make Gecko use seperate CookieContainer per instance?
  • C# Advanced form "please wait"
  • Send and Receive data C# using network stream
  • How to discover that appsettings changed in C#?
  • Check what needs full trust
  • What is the execution order of an MVC Razor view/layout
  • Table designer (Entity Framework) is too resource intense
  • How to clean up an exception string so it can be displayed via Javascript Alert?
  • Configuring Amazon SES Feedback Notifications via Amazon SNS in ASP.NET MVC (C#)
  • C# api responce and request
  • Dynamodb putitem function not working properly
  • theme in windows phone(light or dark) using c#
  • Backup attached database file(.mdf) using c# and SQL Server
  • What is 'TextFile' and where it is uses in WPF project
  • Using same alias for multiple namespaces
  • how to move mails into separate folders
  • Multithreaded Uploader
  • Memory fragmentation?
  • C# correct exception handling
  • "Could not open macro storage" when accessing using file on another machine
  • How to access other directories of hosted server
  • C# Jagged Array check if value exists/true
  • Why can't I type Clone() properly?
  • exception on accessing dictionary from list
  • Getting the immediate response from server without waiting to 200 message
  • Why am I getting exception Directory Is Not empty?
  • Could not load file or assembly 'CefSharp.dll' or one of its dependencies
  • Sending Email By Using C# in unity3D?
  • Correct usage of await async in webapi
  • Program update code issue
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org