出于某种原因,我发现很难理解Serilog配置发生了什么.我有一个带有.NET Core 2.1的web api并已安装serilog.sink.logstash.我的创业公司有:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
var serverURL = Configuration.GetSection("Logging")["logstashServer"];
var logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithProperty("Enviroment", env.EnvironmentName)
.Enrich.WithProperty("ApplicationName", "MyApp")
.WriteTo.LogstashHttp(serverURL);
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
logger.WriteTo.Console();
}
loggerFactory.AddSerilog();
Log.Logger = logger.CreateLogger();
app.UseCors("CorsPolicy");
app.UseMvc();
}
Run Code Online (Sandbox Code Playgroud)
我的appsettings有一节:
"Logging": {
"logstashServer": "http://192.168.0.6:8101",
"IncludeScopes": false,
"Serilog": {
"MinimumLevel": {
"Default": "Error",
"Override": {
"Microsoft": "Error",
"Microsoft.AspNetCore.Hosting": "Error",
"Microsoft.AspNetCore.Mvc": "Error",
"System": "Error"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
无论我做什么,我都会在控制台和logstash中看到,而不是记录很多不需要的信息,如:
[14:27:54 INF]执行的操作方法MyApp.Controllers.LoggerController.Post(MyApp),返回结果Microsoft.AspNetCore.Mvc.OkResult 0.0771ms.
MyApp> [14:27:54 INF]执行HttpStatusCodeResult,设置HTTP状态代码200
MyApp> [14:27:54 INF]执行操作MyApp.Controllers.LoggerController.Post(MyApp)2.0855ms …
我使用.net core 1.1和identityserver 4来获取令牌并验证用户.web api可以很好地从标题中读取持有者令牌并获得用户主要声明.
现在我想使用websocket(而不是SignalR)来发送通知.我可以打开一个ws:// channel(或wss),但令牌不随头文件一起发送,因此在.net核心应用程序中我没有用户信息(用户声明和身份).
如何通过websocket验证用户身份?我做了搜索,但找不到任何有用的信息.
谢谢
我的网站上有一个mp3文件.我想将其输出为视图.在我的控制器中我有:
public ActionResult Stream()
{
string file = 'test.mp3';
this.Response.AddHeader("Content-Disposition", "test.mp3");
this.Response.ContentType = "audio/mpeg";
return View();
}
Run Code Online (Sandbox Code Playgroud)
但是我如何返回mp3文件?
请考虑以下HTML:
<div id="myfavorites">
<p><button id="saveFav">Save my favorites</button> </p>
<p><a href="http://bit.ly/fzgxya">http://bit.ly/fzgxya</a> <a class="favlinks" href="#">(remove me)</a></p>
</div>
Run Code Online (Sandbox Code Playgroud)
按下按钮时,我想用所有链接创建一个json对象.
$('#saveFav').click(function() {
var toSave = { "searchtext" : $('#searchText').val().trim() };
var links = {};
$('#myfavorites p').each(function(index) {
links[index] = $(this).first('a').attr('href');
});
toSave.links = links;
}
Run Code Online (Sandbox Code Playgroud)
但是在$('#myfavorites p')中.每个函数,$(this)都不是p元素.我在这里遗漏了一些东西.如何迭代所有p并找到第一个元素?
我是否正确构建了对象?我的意思是,如果我将它传递给php页面,它会正确地json_decode吗?
谢谢
I am having some trouble with Authorization policies. I have a baseWebApiController with an action
[HttpDelete("{id}"), Authorize(Policy = "Administrator")]
public virtual async Task<IActionResult> Delete(int id) {}
Run Code Online (Sandbox Code Playgroud)
But in a certain controller which inherits from the above I want to give access to users also, with a policy like:
[HttpDelete("{id}"), Authorize(Policy = "All")]
public override Task<IActionResult> Delete(int id){}
Run Code Online (Sandbox Code Playgroud)
It seems regular users cannot access this action. Do I have to search further for errors in my policy configuration, or since the …
我使用cakePHP 3,我在Form-> input()中有一个符号.如果故意我犯了错误,这个错误不会在表单字段下出现.它不会出现在任何地方.
我的代码是这样的:
$newUser = $this->Users->newEntity($this->request->data());
if (!$this->Users->save($newUser)) {
debug($newUser->errors());
$this->Flash->error('Error');
return;
}
Run Code Online (Sandbox Code Playgroud)
Debug显示错误,但是它们不应该自动出现在每个表单元素下面吗?
我正在使用phonegap进行开发和应用.我想使用flexbox来布局我的主应用程序区域中的一些按钮.
有人可以解释为什么这个http://jsfiddle.net/apYLB/不包含最新的chrome中的元素?
HTML:
<div class="flex-container">
<div class="flex-item">1</div>
<div class="flex-item">2</div>
<div class="flex-item">3</div>
<div class="flex-item">4</div>
<div class="flex-item">5</div>
<div class="flex-item">6</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.flex-container {
display: -webkit-box;
display: flex;
flex-wrap: wrap;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
-webkit-flex-direction: row;
-webkit-flex-flow: row wrap;
flex-flow: row wrap;
-webkit-box-align: end;
-moz-box-align: end;
box-align: end;
-webkit-box-pack: center;
-moz-box-pack: center;
box-pack: center;
justify-content:space-around;
height:100%;
}
.flex-item {
margin:0 10px 25px 0;
width:86px;
border:1px solid #000;
}
.flex-item img {
max-height:80px;
}
Run Code Online (Sandbox Code Playgroud)
它们是水平放置的,只有3个半盒子出现.
我正在努力做到以下几点:
var routines = con.Select<Table>(con.From<Table>().OrderBy(p => p.Field1).ThenBy(i => i.Field2));
Run Code Online (Sandbox Code Playgroud)
以上工作完美。但我想要一种更通用的方法并解析像 sort="field1,field2" 这样的字符串。我有以下代码:
int sortFieldCount = 0;
var itemsq = con.From<Table>();
foreach (var name in orderByField.Split(',')) {
if(sortFieldCount == 0)
itemsq = sortOrderAscending ? itemsq.OrderBy(name) : itemsq.OrderByDescending(name);
else
itemsq = sortOrderAscending ? itemsq.ThenBy(name) : itemsq.ThenByDescending(name);
sortFieldCount++;
}
Run Code Online (Sandbox Code Playgroud)
但是上面的代码似乎覆盖了第一个 OrderBy。有没有办法解决这样的问题?
谢谢
asp.net-core ×3
c# ×2
asp.net-mvc ×1
cakephp ×1
cakephp-3.0 ×1
css3 ×1
flexbox ×1
forms ×1
jquery ×1
serilog ×1
sql-order-by ×1
validation ×1
view ×1
websocket ×1