有没有办法在Visual Studio中编写VBA代码.如果没有,还有其他选择吗?
我不小心删除了我的package-lock.json文件.npm install没有生成新的.如何让npm重新创建此文件.
我正在生成JWT以用于我的WebApi项目.我将令牌设置为在一分钟后到期,以便我可以测试它是否在到期日期之后提交时拒绝令牌.
CreateToken控制器
public async Task<IActionResult> CreateToken([FromBody] CredentialModel model)
{
var user = await _unitOfWork.UserManager.FindByNameAsync(model.UserName);
if (user == null) return BadRequest();
if (Hasher.VerifyHashedPassword(user, user.PasswordHash, model.Password) !=
PasswordVerificationResult.Success) return BadRequest();
var userClaims = await UserManager.GetClaimsAsync(user);
var claims = new[]
{
new Claim(JwtRegisteredClaimNames.Sub, user.UserName),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(JwtRegisteredClaimNames.Iat, DateTime.UtcNow.ToString()),
new Claim(JwtRegisteredClaimNames.GivenName, user.FirstName),
new Claim(JwtRegisteredClaimNames.FamilyName, user.LastName),
new Claim(JwtRegisteredClaimNames.Email, user.Email)
}
.Union(userClaims);
var cert = new Certificate(Configuration["Tokens:Certificate"]);
var token = new JwtSecurityToken(
issuer: Configuration["Tokens:Issuer"],
audience: Configuration["Tokens:Audience"],
claims: claims,
expires: DateTime.UtcNow.AddMinutes(1),
signingCredentials: cert.Signature
);
return …
Run Code Online (Sandbox Code Playgroud) 我有一个MVC 6项目,我正在使用Fiddler来测试Web API.如果我采取以下控制器操作,使用EntityFramework 7返回List.然后html将呈现正常.
[HttpGet("/")]
public IActionResult Index()
{
var model = orderRepository.GetAll();
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试返回Json响应时,我得到502错误.
[HttpGet("/")]
public JsonResult Index()
{
var model = orderRepository.GetAll();
return Json(model);
}
Run Code Online (Sandbox Code Playgroud)
关于为什么对象没有正确序列化为json的任何想法?
c# json asp.net-web-api entity-framework-core asp.net-core-mvc
我的所有实体都有四个自定义字段.这四个领域是CreatedBy
,CreatedDate
,UpdatedBy
和UpdatedDate
.
有没有一种方法挂接到实体框架的核心事件,以便对插入它将填充CreatedDate
当前DateTime
和CreatedBy
与当前用户?当有更新,这将填充数据库UpdatedDate
与当前DateTime
和UpdatedBy
与当前用户?
我正在创建一个MVC 6项目,我宁愿使用Classic ADO.net而不是实体框架7.但是,它说两个DataTable
和两个都找不到名称空间SqlDataAdapter
.我有一个使用System.Data
和System.Data.SqlClient
声明.在我尝试构建项目之前,它不显示错误.
我想我在某处看到这两个名字空间没有在新版本中实现.如果是这样,有另一种方法可以做到这一点,还是我错过了依赖或使用声明?
码:
public static DataTable GetLog(string appName)
{
DataTable table = new DataTable("ApplicationLog");
SqlDataAdapter da = null;
using (SqlConnection conn = DB.GetSqlConnection())
{
SqlCommand cmd = new SqlCommand("select * from ApplicationLog where application_name = @appname", conn);
cmd.Parameters.Add(new SqlParameter("appname", System.Data.SqlDbType.NVarChar, 100));
cmd.Parameters["appname"].Value = appName;
da = new SqlDataAdapter(cmd);
int res = da.Fill(table);
}
return table;
}
Run Code Online (Sandbox Code Playgroud)
我的project.json
{
"userSecretsId": "aspnet5-ASPDemo-b25bb1cc-00e6-401e-9f49-5b59c08a030f",
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Bestro": …
Run Code Online (Sandbox Code Playgroud) 我有一个使用的服务ApplicationContext
.所以我想使用依赖注入让应用程序给我上下文.所以我投入了施工
Private _context;
// Constructor
public Service(ApplicationContext context) {
_context = context
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我初始化这个服务时,我必须传递一个上下文,这样它不是真正的依赖注入吗?
有没有办法在不将它放入构造函数参数的情况下注入上下文?
******编辑*****
对不起,我第一次没有提供足够的信息.让我试着更好地解释一下.我有一项服务,我现在只打电话给服务.它读取请求中的头变量,并根据它们的值返回xml.我在控制器的每个不同方法中新建一个实例,因为它们可能具有不同的标头变量值.我想将上下文注入服务而不是控制器,所以我可以这样说:
Service service = new Service(Request);
Run Code Online (Sandbox Code Playgroud)
而不是这个:
Service service = new Service(Request, Context);
Run Code Online (Sandbox Code Playgroud)
服务的原因是在控制器不需要了解任何内容的情况下完成所有工作.我的代码会起作用,但如果我能按照我解释的方式工作,那将会很棒.
如果我们仍然可以在属性上[FromServices].那将是完美的解决方案.不幸的是,这被带走了.这只会将上下文注入到服务或控制器的构造函数中.在这种情况下,我仍然必须将上下文作为参数传递给服务.
有没有办法将上下文注入到服务构造函数中,并避免在创建时将其作为参数传递?
可能会有一个更优雅的解决方案,我很乐意考虑.
c# dependency-injection entity-framework-core asp.net-core-mvc
我正在尝试使用jspm和systemjs将d3 v4导入到打字稿项目中.我可以使用这个正确导入d3
import * as d3 from 'd3';
Run Code Online (Sandbox Code Playgroud)
这有效,它允许我进行选择等.我尝试使用attr函数并传递一个不起作用的对象.我发现d3 v4包含了它作为一个单独的模块.
用jspm下载该模块d3-selection-multi后.我尝试将它导入我的项目中.
import * as d3 from 'd3';
import 'jspm_packages/npm/d3-selection-multi@1.0.0';
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用attrs功能,但控制台记录以下错误
(索引):40错误:(SystemJS)d3.selectAll(...).data(...).style(...).attrs不是函数(...)
我也得到一些编译错误,我一直得到,但他们仍然编译和代码运行
error TS2307: Cannot find module 'd3'
error TS1110: Type expected
Run Code Online (Sandbox Code Playgroud)
谁能解释我做错了什么并提供解决方案?
我正在尝试启动位于SqlServer上的SSIS包。这段代码在.net Framework 4.5.2中有效,但在dotnet核心中出现错误。
码:
var sqlConnection = new SqlConnection("ConnectionString");
var ssis = new IntegrationServices(sqlConnection); // Error on this line of code
var catalog = ssis.Catalogs["CatalogName"];
var folder = catalog.Folders["FolderName"];
var project = folder.Projects["ProjectName"];
var package = project.Packages["PackageName"];
Run Code Online (Sandbox Code Playgroud)
错误
错误CS7069对类型'SqlConnection'的引用声称它在'System.Data'中定义,但找不到
装配体
Microsoft.SqlServer.Management.IntegrationServices.dll
Microsoft.SqlServer.Management.Sdk.Sfc.dll
Microsoft.SqlServer.Smo.dll
System.Data.SqlClient.dll // <-- Via nuget
Run Code Online (Sandbox Code Playgroud)
我有我想念的东西吗?
我在mac上运行.net核心2.1应用程序,我试图访问我的连接字符串,应该被我的用户机密覆盖..csproj文件包含一个guid
<UserSecretsId>{{Secret Guid}}</UserSecretsId>
Run Code Online (Sandbox Code Playgroud)
添加用户密钥
dotnet user-secrets set "ConnectionStrings:DefaultConnection" "Secret Connection String"
Run Code Online (Sandbox Code Playgroud)
我创建了完全从我的appsettings.json文件中读取的配置,但它没有用我的用户机密中的值替换默认值.
// this is done so I build my configurations in a class library
var assembly = AppDomain.CurrentDomain.GetAssemblies()
.Single(o => o.EntryPoint != null);
var configurationBuilder = new ConfigurationBuilder()
.AddEnvironmentVariables()
// .AddUserSecrets<Program>() -> This does not work either
.AddUserSecrets(assembly, optional: false);
configurationBuilder.SetBasePath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
configurationBuilder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
var configuration = configurationBuilder.Build();
Console.WriteLine(configuration["ConnectionStrings:DefaultConnection"]);
Run Code Online (Sandbox Code Playgroud)
正如我之前所说的尝试访问值,它不会用用户机密值替换值.请让我知道我错过了什么.
c# ×6
asp.net-core ×3
ado.net ×1
c#-5.0 ×1
d3.js ×1
excel ×1
excel-vba ×1
json ×1
jspm ×1
jwt ×1
npm ×1
npm-install ×1
sql-server ×1
ssis ×1
systemjs ×1
typescript ×1
vba ×1