小编G. *_*nos的帖子

如何将“允许下载”添加到沙箱属性列表

我正在尝试从我的 MVC 项目(asp.net core 3.1)中获取文件

我创建了一个链接

<a asp-action="@nameof(HomeController.Download)" asp-controller="@HomeController.Name" asp-route-fileName="fileName.doc" download>FileName</a>
Run Code Online (Sandbox Code Playgroud)

我创建了一个控制器

public async Task<ActionResult> Download(string fileName) {
            var path = Path.Combine(_hostingEnvironment.WebRootPath, fileName);
            if (!System.IO.File.Exists(path)) {
                return NotFound();
            }

            var fileBytes = await System.IO.File.ReadAllBytesAsync(path);
            var response = new FileContentResult(fileBytes, "application/vnd.openxmlformats-officedocument.wordprocessingml.document") {
                FileDownloadName = fileName
            };
            return response;
        }
Run Code Online (Sandbox Code Playgroud)

在 Chrome 中我收到警告

不允许下载。启动或实例化下载的帧被沙盒化,但未设置标志“允许下载”。有关更多详细信息,请参阅https://www.chromestatus.com/feature/5706745674465280

按照链接,我如何添加:

将“允许下载”添加到沙箱属性列表以选择加入

如果我单击 Microsoft Edge 中的按钮,则会下载该文件

google-chrome .net-core

6
推荐指数
1
解决办法
1817
查看次数

Serilog 电子邮件接收器启用SSL 错误检查

EnableSsl = false我正在尝试在 my 中使用,但用于连接的smtp 客户端EmailConnectionInfo似乎正在尝试使用 SSL,因为默认设置为. 当我手动创建客户端并使用重载时,它起作用了。smtpSecureSocketOptionsAutoSecureSocketOptions = None

错误:

Failed to send email: MailKit.Security.SslHandshakeException: An error occurred while attempting to establish an SSL or TLS connection.

The SSL certificate presented by the server is not trusted by the system for one or more of the following reasons:
1. The server is using a self-signed certificate which cannot be verified.
2. The local system is missing a Root or …
Run Code Online (Sandbox Code Playgroud)

appsettings serilog asp.net-core

5
推荐指数
1
解决办法
3532
查看次数

正则表达式替换排除第一个和第n个字符

我试图string用*(星号)掩盖名称,并排除第一个和第n个(第5个)字符。

例:

UserFirstName-> U **** F *******

我设法排除的第一个字符用(?!^).

var regex = new Regex("(?!^).");
var result = regex.Replace(stringUserName, "*");
Run Code Online (Sandbox Code Playgroud)

输出:

UserFirstName-> U ************

我还如何排除第5位的角色?

c# regex

5
推荐指数
1
解决办法
61
查看次数