我们在构建服务器上签署可执行文件.突然,构建服务器无法构建错误:
SingTool错误:无法访问sepcified时间戳服务器或返回无效响应.
将时间戳服务器更改为http://sha256timestamp.ws.symantec.com/sha256/timestamp后,唱歌再次起作用.
我知道这有点宽泛我只是不想错过任何东西......
我使用 JWT 令牌进行身份验证
services.AddAuthentication(options =>
{
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(jwtOptions =>
{
jwtOptions.TokenValidationParameters = tokenValidationParameters;
});
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,该[Authorize]属性用于确保调用者需要经过身份验证。这很好用。
但是:如果未经授权的用户发出请求,他会收到 401 响应。我可以以某种方式“中断”此响应并记录未经授权的呼叫吗?
编辑
一个建议是添加一个“异常中间件”,我已经这样做了,但是未经授权的调用不会抛出异常......
services.AddMvc()
.AddMvcOptions(options =>
{
// Order is important! A request will run from top to bottom through each filter.
options.Filters.Add(typeof(MyExceptionFilterAttribute));
});
Run Code Online (Sandbox Code Playgroud)
和属性:
public class MyExceptionFilterAttribute : ExceptionFilterAttribute
{
/// <summary>
/// ctor
/// </summary>
public MyExceptionFilterAttribute()
{
}
/// <summary>
///
/// </summary>
/// <param name="context"></param>
public override void OnException(ExceptionContext context)
{
ApplicationLogger.LogError("Bad request", context.Exception); …Run Code Online (Sandbox Code Playgroud) 在asp.net核心中,当我在程序services.AddMvc().AddXmlSerializerFormatters()中添加一行时;但是在运行时的startup.cs 中出现错误,请大家可以解决这个错误。
我目前正在将硬件库移植到 .NET Core。通信通过 TCP 进行。我对 'Socket.BeginReceive' 方法有问题。MSDN
.NET Core 中似乎没有等效的方法。如何从 TCP 套接字接收数据?
private void InternalDataReceived(IAsyncResult ar)
{
int dataCount = 0;
byte[] buffer;
try
{
if (_client != null && _client.Client != null)
{
dataCount = _client.Client.EndReceive(ar);
}
if (dataCount > 0)
{
try
{
buffer = new byte[dataCount];
Array.Copy(_inBuffer, buffer, dataCount);
if (DataReceived != null)
{
DataReceived(buffer);
}
}
catch (Exception exc)
{
if (exc is System.Net.Sockets.SocketException)
{
Disconnect();
return;
}
}
_client.Client.BeginReceive(_inBuffer, 0, _inBuffer.Length, SocketFlags.None, InternalDataReceived, null); …Run Code Online (Sandbox Code Playgroud) 目前我有一个ExceptionFilterAttribute来处理controllers. 我的 API 连接到服务(通过专有的 TCP/IP)。如果此服务无法访问,我想返回 HTTP 504 响应代码以及正确的错误消息。
我已经弄清楚如何发送 400
public override void OnException(ExceptionContext context)
{
if (!MyService.IsConnected)
{
context.Result = new BadRequestObjectResult(new ResultInformation() { ResultCode = 2000056, Message = "My service is not reachable" });
}
else
{
context.Result = new BadRequestObjectResult(new ResultInformation() { ResultCode = 0, Message = context.Exception.Message });
}
}
Run Code Online (Sandbox Code Playgroud)
如何更改此代码以发送 504 和错误消息?
我们只是从Application Insights开始。尽管它主要是针对在云中运行的应用程序构建的,但我们也使用它来跟踪WPF客户端的一些使用情况统计信息。
对于此安装,我们不想跟踪cloud_RoleInstance中的计算机名称。这是我们的隐私政策问题。与小型公司一样,存储计算机名称甚至变得更加关键,计算机名称可能是用户名。至少在我们的市场上,这是不可行的。
这就是为服务器和WPF客户端设置遥测客户端的方式。
TelemetryClient telemetryClient = new TelemetryClient() { InstrumentationKey = ApplicationInsightsHelper.InstrumentationKey };
//do not track username...
//telemetryClient.Context.User.Id = Environment.UserName;
telemetryClient.Context.Session.Id = SessionId.ToString();
telemetryClient.Context.Device.OperatingSystem = GetWindowsFriendlyName();
telemetryClient.Context.Component.Version = Version;
telemetryClient.Context.Properties.Add("ComponentName", ComponentName);
telemetryClient.Context.Properties.Add("CustomerId", CustomerId);
Run Code Online (Sandbox Code Playgroud)
现在,我的问题是如何设置遥测客户端以删除,混淆,覆盖cloud_RoleInstance属性。
提前致谢