草庐IT

controller_action_predispatch_che

全部标签

c# - 从任意 URL 手动实例化 Controller 实例?

我的技能让我失望了,我知道我已经看过相关代码,但找不到它。获取任意URL、通过asp.netmvc路由系统运行它并在另一端产生对Controller实例的引用的最快方法是什么?例如,代码执行在某个任意Controller方法中。我想做这样的事情:...stringmyURL="http://mysite/mycontroller/myaction/myparameters";RouteDatafakeRouteData=newRouteData(Route???,IRouteHandler???)RequestContextctxt=newRequestContext(this.Con

c# - 创建一个 Action<T> 到 "set"属性,当我为 "get"提供 LINQ 表达式时

我希望能够生成编译表达式来设置属性,给定为属性提供“get”方法的lambda表达式。这是我正在寻找的:publicActionCreateSetter(Expression>getter){//returnsacompiledactionusingthedetailsofthegetterexpressiontree,ornull//ifthewritepropertyisnotdefined.}我仍在努力理解各种类型的Expression类,因此,如果您能为我指明正确的方向,那就太好了。 最佳答案 以@Ani的回答为起点,您可以

c# - 特定于 ASP.NET Web API 中的 Controller 的自定义委托(delegate)处理程序

我编写了一个自定义委托(delegate)处理程序,它向请求中的响应和检查添加自定义header。我在WebAPI配置中添加了句柄config.MessageHandlers.Add(newcustomHandler());但问题适用于所有Controller。我需要应用特定于Controller的自定义header。是否可以添加特定于Controller的自定义处理程序? 最佳答案 本文末尾解释了如何将处理程序仅应用于某些路由:http://www.asp.net/web-api/overview/working-with-htt

c# - 使用 ASP.NET Web API, Controller 如何返回使用 DotNetZip 库压缩的流图像集合?

我如何创建一个WebAPIController来生成并返回从内存中JPEG文件(MemoryStream对象)集合流式传输的压缩zip文件。我正在尝试使用DotNetZip库。我找到了这个例子:https://web.archive.org/web/20211020131216/https://www.4guysfromrolla.com/articles/092910-1.aspx#postadlink。但是Response.OutputStream在WebAPI中不可用,因此该技术不太有效。因此,我尝试将zip文件保存到新的MemoryStream;但它扔了。最后,我尝试使用Pus

c# - 无法将带有 [] 的索引应用于 mvc Controller 中类型为“System.Collections.Generic.ICollection<int>”的表达式

publicActionResultaddstandardpackage1(ICollectionSingleStay,ICollectionDOUBLESTAY,ICollectionTRIBLESTAY,ICollectionFAMILYSTAY,ICollectionEXTRABED){vars=SingleStay;for(inti=0;i在for循环中,我收到类似无法将带[]的索引应用于类型表达式的错误,但我需要在for循环中,在我得到的每个中。因为基于for循环,我会将详细信息与其他集合列表绑定(bind)。请帮助我。我在varcal=Singlestay[i]中遇到错误。

c# - 如何在 ASP.NET CORE 中使用具有依赖注入(inject)的 Action 过滤器?

我在我的ASP.NETCORE应用程序中到处使用基于构造函数的依赖注入(inject),我还需要在我的操作过滤器中解析依赖关系:publicclassMyAttribute:ActionFilterAttribute{publicintLimit{get;set;}//somecustomparameterspassedfromActionprivateICustomServiceCustomService{get;}//thismustberesolvedpublicMyAttribute(){}publicoverrideasyncTaskOnActionExecutionAsyn

c# - 发现多个类型与名为 'Home' 的 Controller 匹配 - 在两个不同的区域

我的项目有两个区域。现在,当我运行该程序时,出现此错误:Multipletypeswerefoundthatmatchthecontrollernamed'Home'.Thiscanhappeniftheroutethatservicesthisrequest('{controller}/{action}/{id}')doesnotspecifynamespacestosearchforacontrollerthatmatchestherequest.Ifthisisthecase,registerthisroutebycallinganoverloadofthe'MapRoute'm

c# - 为什么 Asp.net MVC 不能区分具有不同参数的两个 Action ?

我正在尝试在我的Asp.netMVC应用程序中使用两种不同的帐户注册方法,一种供一般用户注册,另一种供使用特定注册token注册的用户使用。因此,我的AccountController中有以下方法签名:publicvirtualActionResultRegister(){...}publicvirtualActionResultRegister(GuidregistrationToken){...}但是,当我转到http://localhost/Account/Register时,我得到一个异常,即当前请求在这两个操作之间不明确。我的印象是,如果没有传入registrationTok

c# - 从 ASP MVC 中的区域 Controller 链接到根 Controller

如何从我的区域之一链接到我的根Controller之一?这给了我一个错误:Norouteintheroutetablematchesthesuppliedvalues.我的根Controller集合中名为Admin的文件夹中有一个名为Page的Controller。我可以通过键入\Admin\Page访问此Controller。这是我注册路线的方式:routes.MapRoute("Admin","Admin/{controller}/{action}/{id}",new{controller="Admin",action="Index",id=""});我希望我可以使用我认为的这种语

c# - Autofac - 确保 Controller 有一个无参数的公共(public)构造函数

我知道之前有人问过这个问题并回答过-我问这个问题的原因是(我认为)我尝试了所有建议的解决方案来解决这个问题,但仍然无法解决。我有一个ASP.NETWebAPI2.0项目。我安装了Autofac、Autofac.Mvc5和Autofac.WebApi2依赖项。当我尝试调用APIController时,出现以下错误:Anerroroccurredwhentryingtocreateacontrolleroftype'MyController'.Makesurethatthecontrollerhasaparameterlesspublicconstructor.在我的Global.asax