为了账号安全,请及时绑定邮箱和手机立即绑定

为 Autofac 中的嵌套依赖项提供类型化参数

为 Autofac 中的嵌套依赖项提供类型化参数

C#
大话西游666 2022-10-23 16:41:31
使用 .NET Core 包Syncfusion.EJ2.WordEditor.AspNet.Core,我可以将 doc(x) 文件转换为 sfdt 格式。因此,我使用 Visual Studio 2017 For Mac 使用此包创建了一个新的 .NET Core Web Api 应用程序。using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.Mvc;using Syncfusion.EJ2.DocumentEditor;namespace SyncfusionConverter.Controllers{    [Route("api/[controller]")]    public class SyncfusionController : Controller    {        [AcceptVerbs("Post")]        public string Import(IFormCollection data)        {            if (data.Files.Count == 0)                return null;            Stream stream = new MemoryStream();            IFormFile file = data.Files[0];            int index = file.FileName.LastIndexOf('.');            string type = index > -1 && index < file.FileName.Length - 1 ?            file.FileName.Substring(index) : ".docx";            file.CopyTo(stream);            stream.Position = 0;            WordDocument document = WordDocument.Load(stream, GetFormatType(type.ToLower()));            string sfdt = Newtonsoft.Json.JsonConvert.SerializeObject(document);            document.Dispose();            return sfdt;        }        internal static FormatType GetFormatType(string format)        {            if (string.IsNullOrEmpty(format))                throw new NotSupportedException("EJ2 DocumentEditor does not support this file format.");            switch (format.ToLower())            {                case ".dotx":                case ".docx":                case ".docm":            }        }    }}我发出 Ajax 请求,以我的 doc(x) 文件作为参数调用此 .Net 方法。执行 loadFile 函数时,我在浏览器的控制台中收到此错误:“跨源请求(阻止多源请求):“同源”策略不允许查阅位于https://localhost上的远程资源:5001/Syncfusion/Import。原因:CORS 请求失败。”我按照本教程和那些 SO 发布Link1 Link2但它不起作用。有什么想法可以解决这个问题吗?
查看完整描述

1 回答

?
开心每一天1111

TA贡献1836条经验 获得超13个赞

简短的回答:您不能将参数传递给解析链中间的东西。

这是 Autofac 文档中的常见问题解答。


查看完整回答
反对 回复 2022-10-23
  • 1 回答
  • 0 关注
  • 134 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号