我无法理解的是,是否可以对上下文进行更改并在提交之前在同一事务中获取更改.
这就是我要找的:
using (var scope = new TransactionScope(TransactionScopeOption.Required))
{
using (var context = new DbContext())
{
//first I want to update an item in the context, not to the db
Item thisItem = context.Items.First();
thisItem.Name = "Update name";
context.SaveChanges(); //Save change to this context
//then I want to do a query on the updated item on the current context, not against the db
Item thisUpdatedItem = context.Items.Where(a=>a.Name == "Update name").First();
//do some more query
}
//First here I want it …Run Code Online (Sandbox Code Playgroud) c# transactionscope savechanges dbcontext entity-framework-6
我找不到有关如何在Visual Studio 2015上安装.Net Core的SDK的活动链接的任何正确解释.
我迷了,请告知如何在VS 2015上安装它?
在我的Web Api 2.2基于OWIN的应用程序中,我有一种情况,我手动需要解码承载令牌,但我不知道如何做到这一点.这是我的startup.cs
public class Startup
{
public static OAuthAuthorizationServerOptions OAuthServerOptions { get; private set; }
public static UnityContainer IoC;
public void Configuration(IAppBuilder app)
{
//Set Auth configuration
ConfigureOAuth(app);
....and other stuff
}
public void ConfigureOAuth(IAppBuilder app)
{
OAuthServerOptions = new OAuthAuthorizationServerOptions()
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
Provider = new AuthProvider(IoC.Resolve<IUserService>(), IoC.Resolve<IAppSettings>())
};
// Token Generation
app.UseOAuthAuthorizationServer(OAuthServerOptions);
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
}
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我发送了承载令牌作为参数
[RoutePrefix("api/EP")]
public class EPController : MasterController
{
[HttpGet]
[AllowAnonymous]
[Route("DC")]
public async …Run Code Online (Sandbox Code Playgroud) 假设我有一堂课
public class product
{
public string GetName()
{
return "product";
}
public static string GetStaticName()
{
return "product";
}
}
Run Code Online (Sandbox Code Playgroud)
这些方法做同样的事情,但一个是静态的,一个不是.
当我调用这些方法时,我这样做:
product p = new product();
string _ProductName = p.GetName();
Run Code Online (Sandbox Code Playgroud)
和
string _ProductName = product.GetStaticName();
Run Code Online (Sandbox Code Playgroud)
哪种方法最适合用于性能等?
这是我的Startup.cs,我将索引页面映射到路径'/ app'.
...
using Microsoft.Owin.FileSystems;
using Microsoft.Owin.StaticFiles;
using Microsoft.Owin.Diagnostics;
[assembly: OwinStartup(typeof(conApi.Startup))]
namespace conApi
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
////Set static files
ConfigureFiles(app);
//Enable Cors
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
}
public void ConfigureFiles(IAppBuilder app)
{
app.Map("/app", spa =>
{
spa.Use((context, next) =>
{
context.Request.Path = new PathString("/index.html");
return next();
});
spa.UseStaticFiles();
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
它就像一个魅力,但我不知道如何配置客户端缓存.我想知道如果在使用OWIN静态文件时可以设置Expires标头?
解决方案
Tratcher提供了StaticFilesOptions类文档等的链接,这些链接引导我找到解决方案.将StaticFilesOptions添加到ConfigureFiles方法,如下所示:
public void ConfigureFiles(IAppBuilder app)
{
var staticFileOptions = new StaticFileOptions
{
OnPrepareResponse = (StaticFileResponseContext) =>
{
StaticFileResponseContext.OwinContext.Response.Headers.Add("Cache-Control",new[] { "public", "max-age=1000" }); …Run Code Online (Sandbox Code Playgroud) 这是我的输入
<input type="number" id="inputNumbers" step="0.01" ></input>
Run Code Online (Sandbox Code Playgroud)
是否可以只允许用户输入与模式“0.00”匹配的数字,就像我在 step 属性中声明它的方式一样,而不使用 JavaScript?
示例:如果用户键入“1.23”,然后尝试输入新数字、小数点或逗号,则无法输入,并且数字保持为“1.23”。
如果没有匹配 step 属性的方法,是否可以只允许数字中的一位小数?
当我使用此方法的标题键名称时,我能够逐个获取请求标头
private string GetHeader(string Name)
{
IEnumerable<string> headerValues;
if (Request.Headers.TryGetValues(Name, out headerValues))
{
return headerValues.FirstOrDefault();
}
else { return ""; }
}
Run Code Online (Sandbox Code Playgroud)
但我真正想要的是获取所有请求标头并将它们存储在字典中,就像这样
Dictionary<string, string> ss = Request.Headers.ToDictionary(a => a.Key, a => a.Value);
//this doesn't work
Run Code Online (Sandbox Code Playgroud)
有谁知道如何做到这一点?
我在文件中有以下内容并读作
var input = require("./mydata.json");
"User": {
"properties": {
"firstName": {
"type": "string",
"minLength": 1,
"maxLength": 50
},
"lastName": {
"type": "string",
"maxLength": 50
},
"middleName": {
"type": "string"
},
"title": {
"type": "string"
},
"language": {
"type": "string",
"default": "en-US"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我使用下面的代码循环键
var item = _.get(input, 'User');
var properties = item.properties;
var allKeys = _.keys(properties);
_.each(allKeys, function(key) {
});
Run Code Online (Sandbox Code Playgroud)
在每个循环中,我得到firstname,lastname等,与输入文件中的顺序相同.我想知道我是否会按顺序得到它?
我已经创建了一个运行grafana docker映像的网络应用,如下所示
az group create --name grp-test-container-1
--location "West Europe"
az appservice plan create --name asp-test-container-1
--resource-group grp-test-container-1
--sku B1
--is-linux
az webapp create --resource-group grp-test-container-1
--plan asp-test-container-1
--name app-test-container-1
--deployment-container-image-name grafana/grafana:latest
Run Code Online (Sandbox Code Playgroud)
然后我更新了appsettings以便将env变量传递给docker run命令
az webapp config appsettings set --name app-test-container-1
--settings GF_INSTALL_PLUGINS='grafana-azure-monitor-datasource'
--resource-group grp-test-container-1
Run Code Online (Sandbox Code Playgroud)
然后,我需要重新启动容器,以便在docker run命令中获取添加的env变量。
我试图重新启动Web应用程序,停止/启动它,更改docker映像名称并保存在Container Settings下。
有什么建议么?
正如Charles Xu在回答中所说,要重新加载容器,您需要更改docker映像并保存,以使Web应用程序再次获取该映像并应用添加的env变量。
就我而言,我做了更改,然后查看了日志输出,但是日志从未更新过。我等待了5-10分钟,但仍然没有添加日志。
但是,当我访问该站点并浏览到由env变量安装的扩展程序时,我可以确定一切都已通过。
因此,总结一下:容器设置中的日志是不可信的,进行更改时,这些更改可能不会显示在日志中。
我已经确定了这些预定义的响应:
Ok - 200
NotFound - 404
Exception - 500
Unauthorized - 401
BadRequest - 400
Conflict
Redirect
InvalidModelState
Run Code Online (Sandbox Code Playgroud)
但我找不到任何有关现有辅助方法总范围的文档..还有更多吗?
我试过微软网站,只找到了这些文档,但他们根本没有列出它们。
感谢帮助
我是这个引导加载程序的新手。我使用 SWD 对 stm3205 进行编程。所以当我对 stm32f05 微控制器进行编程时,我的程序在哪个位置。我可以制作自己的引导加载程序并将其替换为 st 的默认引导加载程序吗?
假设我有一个身份验证方法,我可以通过 http post 从服务器获取令牌:
$http({
method: 'POST',
url: '/Token',
processData: false,
contentType: 'application/x-www-form-urlencoded',
data: "grant_type=password&username=" + UserName + "&password=" + Password
...
Run Code Online (Sandbox Code Playgroud)
在这里,我以明文形式发送用户名和密码。
如果我使用 JavaScript 函数 btoa() 加密我的用户名和密码(该函数很好用,建议使用How can you Encode a string to Base64 in JavaScript?),如下所示:
$http({
method: 'POST',
url: '/Token',
processData: false,
contentType: 'application/x-www-form-urlencoded',
data: "grant_type=password&username=" + btoa(UserName) + "&password=" + btoa(Password)
...
Run Code Online (Sandbox Code Playgroud)
这对我真正帮助我应对哪些安全威胁?我的意思是,事实上,我网站上的任何人都可以访问我的 javascript 代码,因此可以找到调用 btoa() 的脚本。然后他们可以使用 atob() 解密用户名和密码,然后我又回到了第一步。
c# ×7
owin ×3
javascript ×2
.net-core ×1
azure ×1
base64 ×1
bearer-token ×1
bootloader ×1
caching ×1
dbcontext ×1
docker ×1
html ×1
json ×1
oauth-2.0 ×1
savechanges ×1
stm32 ×1