Tag: asp.net mvc

使用Ocelot重新路由错误asp.net Core(7.0.4)

“ReRoutes”: [ { “DownstreamPathTemplate”: “/api/Agent/GetPagedAgents?page={page}”, “DownstreamScheme”: “http”, “DownstreamHostAndPorts”: [ { “Host”: “agent.api”, “Port”: 80 } ], “UpstreamPathTemplate”: “/api/account/user/list/GetPagedAgents?page={page}”, “UpstreamHttpMethod”: [] }] 在这里,我试图从查询字符串重新路由我的UpstreamPathTemplate到DownstreamPathTemplate, “http://accountmanagement/api/account/user/list/GetPagedAgents?page=1” 这是我的查询字符串,我发送到我的帐户管理服务,使用ocelot重新路由到我的代理服务。 这是我在代理服务中的Controller方法,用于接收重新路由的路径 [HttpGet] [Route(“GetPagedAgents”)] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.BadRequest)] public IActionResult Get(string page, string pageSize, string filter, string sortBy) { var Result = _agentServices.GetAll(Convert.ToInt32(page), Convert.ToInt32(pageSize),filter,sortBy); return Ok(Result); } 但它不起作用。 在我的OUTPUT窗口中显示消息:无法找到路径的下游路由:/ api / account / user […]

为Web API 1,.net 4.0启用CORS

我需要为我的Web API启用CORS,目前我无法升级到Framework 4.5。 (我了解System.Web.Http.Cors.EnableCorsAttribute。) 我试图将以下内容添加到我的Web.config中以查看它是否有效,但它没有: 我还试图通过使用System.Web.Http.Filters.ActionFilterAttribute手动将Access-Control-Allow-Origin标头设置为“*”(基于这篇文章: 向Web API中的所有响应添加自定义标头 ) -但由于请求在进入动作过滤之前被拒绝,因此无法解决问题。 所以我现在有点卡住..任何帮助都表示赞赏。 编辑:结果 一直都是答案,我在测试之前一定做错了。 但是这个解决方案意味着所有操作都启用了CORS(现在可以使用)。

Asp.Net Identity Localization PublicKeyToken

我试图通过使用以下post的建议来获取瑞典语对Asp.Net Identity的本地化错误消息: 如何本地化ASP.NET Identity UserName和Password错误消息? 使用NuGet我下载了德语语言包,然后在dotPeek中打开\ packages \ Microsoft.AspNet.Identity.Core.2.0.0 \ lib \ net45 \ de \ Microsoft.AspNet.Identity.Core.resources.dll,然后将其导出到一个新的VS项目: https://github.com/nielsbosma/AspNet.Identity.Resources.Swedish/ 我已将生成的\ Microsoft.AspNet.Identity.Core.resources.dll复制到\​​ packages \ Microsoft.AspNet.Identity.Core.2.0.0 \ lib \ net45 \ se下的新文件夹。 当我在本地运行我的网站时,我看到Microsoft.AspNet.Identity.Core.resources.dll已被复制到MySite \ bin \ sv \ 但我不能让它工作:( 如果我在我的Web.config中设置: … 我仍然得到英文默认错误消息。 但如果我改为德语,我已经从NuGet中包含了我收到德语错误消息。 使用dotPeek我将我的dll与德语进行了比较,除了我的PublicKeyToken = null和德语为“31bf3856ad364e35”之外,它们是相同的。 这可能是我无法加载我的DLL的原因吗? 无论如何为dll设置PublicKeyToken? 任何解决方法? 谢谢你的任何指示。

将数组作为JSON发布到MVC控制器

我一直在努力寻找这个问题的解决方案。 在我的代码中,我正在构建一个对象数组; var $marks = []; var mark = function ( x, y, counter ){ this.x = x; this.y = y; this.counter = counter; } $marks.push(new mark(1, 2, 0)); $marks.push(new mark(1, 2, 1)); $marks.push(new mark(1, 2, 2)); 现在我想将这些数据发布到MVC控制器,所以我认为控制器中的数据类型将是List Marks或Marks数组。 为了发布数据,我试过了; var json = JSON.stringify($marks); $.post(‘url’, json).done(function(data){ /* handle */ }); 要么 var json = { […]

无法在Web API中正确获取文件扩展名

我在ASP.NET MVC和Angular的项目构建中使用了一个方法并检索从数据库中存储的文件而没有任何问题: [HttpPost] public ActionResult GetFile(int id) { var file= service.GetFileById(id); if (file.Data != null) { return File(file.Data, file.MimeType, file.Name); } return new EmptyResult(); } 另一方面,当我想在我的Web Api控制器中使用相同的方法时,没有这种类型的File()方法,我在查看stackoverflow上的15-20解决方案之后尝试使用以下方法: [Route(“api/Generate/{id}”)] [AcceptVerbs(“GET”, “POST”)] public HttpResponseMessage Generate(int id) { var data = service.GetFileByName(id); var stream = new MemoryStream(); var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(stream.ToArray()) }; […]

现在用视觉开始执行石英计划,间隔24小时

我创建了一个爬虫,它从我之前定义的其他网站获取新闻,因此我使用quartz在后台运行任务。计划定义如下: public class JobBackground : IJob { public void Execute(IJobExecutionContext context) { for (int j = 1; j <= 920; j++) { NewsRepository newsRepository = new NewsRepository(); GoyaAgent Goyaagent = new GoyaAgent(); Task<List> lst = Goyaagent.parsing(“http://www.gooyait.com/page/”+j); List enresult = lst.Result; foreach (NewsContent newsContent in enresult) { News newnews = new News(); newnews.Subject = newsContent.Title; newnews.NewsDate […]

为什么在MVC4 Razor View中找不到扩展方法?

给出以下字符串扩展方法 namespace JHS.ExtensionMethods { public static class StringExtensions { public static string ToUSAPhone(this String str) { return String.Format(“{0:(###) ###-####}”, Double.Parse(str)); } } } @using语句被添加到MVC4 Razor视图中 @using JHS.ExtensionMethods; 以下字符串值调用扩展方法 @Model.producer.phone.ToUSAPhone() 这会导致以下错误 ‘string’ does not contain a definition for ‘ToUSAPhone’ 我还尝试将命名空间放在/ Views文件夹的web.config中并收到相同的错误。 我通过在C#类中调用相同的调用来validation扩展方法的工作原理 string test=producer.phone.ToUSAPhone(); 看来扩展方法的引用在MVC4 Razor视图中不可用,但我无法弄清楚为什么?

MVC4 webapi中的反序列化/模型绑定不适用于数组

我正在使用新的WebApi,它是MVC4 beta的一部分。 我有以下课程: public class Voucher { public string Id { get; set; } public string TableId { get; set; } public Product[] Products { get; set; } } 我的控制器看起来像这样: public class VouchersController : ApiController { public Voucher PostVoucher(Voucher voucher) { //…. } } 在客户端,我使用XmlSerializer序列化数据。 输出看起来像预期的那样, Products数组是序列化的。 如果我发布数据并在PostVoucher方法中放置一个断点,我会获得Id和TableId的数据,但Products为null 。 什么暗示我可能做错了什么?

针对ApplicationUser Roles导航属性的ASP MVC Build Throwing Warning?

我有以下ApplicationUser模型: public class ApplicationUser : IdentityUser { public string FirstName { get; set; } public string LastName { get; set; } public virtual ICollection Roles { get; set; } public bool HasRole(string _role) { return Roles.Any(r => r.Name == _role); } public bool HasPermission(string _permission) { return Roles.Any(r => r.Permissions .Any(p => p.Name == _permission)); […]

web.config转换从web.template.xml无法正常工作

我正在尝试按照此处所述进行web.config转换。 我们已经在其他项目中使用了这种方法,它没有问题,但在这个新项目上没有。 这是我试过没有成功的测试 在我得到项目名称错误的情况下更改wpp.targets文件的名称。 我知道我正在使用的当前工作,因为它是唯一一个导致从web.template.xml重建web.config的转换工作。 只有子模板不起作用。 尝试使用xdt:Locator =“Match(name)” 尝试.config扩展与.xml,我们的其他项目使用.xml 配置管理器设置为我正在使用的项目使用“测试”配置。 web.template.Test.xml对我要替换的部分有xdt:Transform =“Replace” web.template.xml具有占位符 尝试从wpp.targets中删除“CopyWebTemplateConfig”部分,如下面链接的堆栈问题所示。 我们的其他项目有这个和“PropertyGroup”部分注释掉,我尝试了两种组合。 我已经多次阅读了上面的链接和这个相关的堆栈问题 ,但看不出是什么问题。 注意发布转换确实有效。 它创建一个web.template.xml文件,其中包含来自web.template.Test.xml的值,但不会像wpp.targets指示的那样创建web.config.xml。 所以这似乎是让构建转换正常工作的问题。 任何人都知道缺少什么? wpp.targets $(PrepareForRunDependsOn); UpdateWebConfigBeforeRun; web.template.xml …. …. …. web.template.Test.xml … MSBuild输出 Target “UpdateWebConfigBeforeRun: (TargetId:143)” in file “C:\…\Project.wpp.targets” from project “C:\…\Project.csproj” (target “PrepareForRun” depends on it): Task “Message” (TaskId:93) Configuration: Test: Web.template.Test.xml (TaskId:93) Done executing task […]