1. 在使用singleton时出现 Cannot resolve scoped service 'AlgoTag.Models.AlgoContext' from root provider.
https://www.cnblogs.com/liuzeqi/p/14132325.html
原因:一般情况下,生命周期较长的服务不应该依赖一个生命周期较短的服务,Scope的服务被Singleton的服务依赖/引用,那么这个Scope的服务也会随依赖它的Singleton服务变成Singleton的。
ref: service 有参构造: https://www.cnblogs.com/nickyX/p/14731137.html
2. 在IIS里如何访问Linux系统的共享文件夹
第一种方式: 在代码中实现 https://www.cjavapy.com/article/395/, git源码: https://github.com/zinkpad/SharpCifs 这种方式我没有尝试过。
第二种方式:模拟登录:https://blog.csdn.net/cxu123321/article/details/108592475 我采用了方案一,利用WindowsAPI :
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace ConsoleApplication5 { public class SharedTool : IDisposable { // obtains user token [DllImport("advapi32.dll", SetLastError = true)] static extern bool LogonUser(string pszUsername, string pszDomain, string pszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken); // closes open handes returned by LogonUser [DllImport("kernel32.dll", CharSet = CharSet.Auto)] extern static bool CloseHandle(IntPtr handle); [DllImport("Advapi32.DLL")] static extern bool ImpersonateLoggedOnUser(IntPtr hToken); [DllImport("Advapi32.DLL")] static extern bool RevertToSelf(); const int LOGON32_PROVIDER_DEFAULT = 0; const int LOGON32_LOGON_NEWCREDENTIALS = 9;//域控中的需要用:Interactive = 2 private bool disposed; public SharedTool(string username, string password, string ip) { // initialize tokens IntPtr pExistingTokenHandle = new IntPtr(0); IntPtr pDuplicateTokenHandle = new IntPtr(0); try { // get handle to token bool bImpersonated = LogonUser(username, ip, password, LOGON32_LOGON_NEWCREDENTIALS, LOGON32_PROVIDER_DEFAULT, ref pExistingTokenHandle); if (bImpersonated) { if (!ImpersonateLoggedOnUser(pExistingTokenHandle)) { int nErrorCode = Marshal.GetLastWin32Error(); throw new Exception("ImpersonateLoggedOnUser error;Code=" + nErrorCode); } } else { int nErrorCode = Marshal.GetLastWin32Error(); throw new Exception("LogonUser error;Code=" + nErrorCode); } } finally { // close handle(s) if (pExistingTokenHandle != IntPtr.Zero) CloseHandle(pExistingTokenHandle); if (pDuplicateTokenHandle != IntPtr.Zero) CloseHandle(pDuplicateTokenHandle); } } protected virtual void Dispose(bool disposing) { if (!disposed) { RevertToSelf(); disposed = true; } } public void Dispose() { Dispose(true); } } }
3. 当使用ajax获取到后台返回image/jpeg 的图片时如何在页面上用jquery显示出来
function GetNextImage(i) { $.ajax({ url: "/Home/GetNextImage/" + i, type: "get", xhrFields: { responseType: 'blob' }, success: function (data) { var img = i == 0 ? $("#topimg") : $("#bottomimg"); var reader = new FileReader(); reader.onload = function (e) { img.css("background-image", "url(" + e.target.result + ")"); } reader.readAsDataURL(data); }, error: function (e) { alert(e); } });
需要设定responseType 为 blob。
如果是直接显示在页面上的话,那么可以把URL直接设给src 属性:
<img style="background-image: url('/Home/Image'); background-position:-324px 0px;" width="1800" height="720"/>
4. 下载下来的UTF-8编码格式的csv文件,直接用Excel打开是乱码的问题。
用notepad++ 打开没有问题, 用notepad++ 转换成UTF-8 BOM 保存后再用Excel打开也没有问题。所以在服务器上应该给文件内容加上BOM 头。
引用以下 答案: https://stackoverflow.com/questions/4414088/how-to-getbytes-in-c-sharp-with-utf8-encoding-with-bom
public IActionResult Download() { var data = Encoding.UTF8.GetBytes("some data"); var result = Encoding.UTF8.GetPreamble().Concat(data).ToArray(); return new FileContentResult(result, "text/plain;charset=utf-8") { FileDownloadName = "数据汇总.csv" }; }
标签:CORE,ASP,string,IntPtr,int,bool,https,new,NET From: https://www.cnblogs.com/crazyghostvon/p/17129407.html