小编NiA*_*iAu的帖子

.NET Core 3.1 API - 307 临时重定向

将我的 .NET Core 2.2 API 升级到 .NET Core 3.1 时,需要进行大量更改。我不得不更新 Swashbuckle 包并更改启动文件。我现在使用 Swagger 在开发中运行它。

一旦发布到在 IIS 上运行的 Windows 2012 服务器,每个 API 调用都会返回 307 临时重定向。

在启动中,我必须删除 UseMvc 并添加 UseEndpoints

if (env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}
else
{
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

if (!env.IsProduction())
{
    app.UseSwagger();
    app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Digital Signatures V1"); });
}

app.UseMiddleware<LogContextMiddleware>();

app.UseMiddleware<CustomExceptionMiddleware>();

app.UseHttpsRedirection();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
    endpoints.MapControllers();
});
Run Code Online (Sandbox Code Playgroud)

有没有人知道为什么我得到这个重定向状态?

在 …

api rest http-status-code-307 asp.net-core-3.1

5
推荐指数
2
解决办法
3890
查看次数

Serilog Logcontext 属性在异常处理程序之后消失了

在我的网站中,我正在集成 Serilog 以将我的错误记录到自定义接收器中。LogContext 丰富了日志记录,其中需要传递一些自定义属性。如果我使用 Log.Information(),它会使用 LogEvent 中的属性到达我的接收器。所以这很好用。

主要目的是将日志系统与异常处理程序中间件结合起来。所以在异常处理程序中,错误被捕获,这是从控制器方法抛出的。我将 _logger.Log() 放在异常处理程序中的任何地方,Sink 中都没有可用的自定义属性。在调试时,它在进入 Sink 之前通过了 LogContextFilter,但没有找到过滤器的属性。

有没有人有任何想法?

启动

Log.Logger = new LoggerConfiguration()
            .WriteTo.PasSink(new SerLogServiceClient.SerLogServiceClient(new SerLogServiceClientOptions()))
            .Enrich.FromLogContext()
            .CreateLogger();

services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2).AddMvcOptions(mo =>
        {
            mo.Filters.Add(typeof(LogContextFilter));
        });

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseMiddleware<LogContextMiddleware>();
        app.UseErrorHandler(o =>
        {
            o.ExceptionHandlingPath = "/Home/Error";
            o.Context = ExceptionHandler.Context.MVC;
        });

        //app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseStaticFiles(new StaticFileOptions
        {
            FileProvider = new PhysicalFileProvider(
                Path.Combine(Directory.GetCurrentDirectory(), "Content")),
            RequestPath = "/Content"
        });

        app.UseAuthentication();

        app.UseSession();
        //app.UseCookiePolicy();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
Run Code Online (Sandbox Code Playgroud)

日志上下文过滤器

public async Task …
Run Code Online (Sandbox Code Playgroud)

c# error-handling asp.net-mvc serilog asp.net-core

4
推荐指数
1
解决办法
1650
查看次数

Xamarin表单旋转Listview调整行宽

在Xamarin Forms中,我想实现水平列表视图(如下图所示)。通过旋转可以实现,但是我不能更改行宽。还有可能让第二个布局在第一个之下开始吗?提前致谢!

 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="Recipe.Pages.SearchPage"
         Title="Search">
<ContentPage.Content>
<StackLayout Spacing="5" x:Name="layout" Orientation="Vertical" >
  <StackLayout x:Name="layoutButtons" HorizontalOptions="FillAndExpand" Orientation="Horizontal" Spacing="5" BackgroundColor="Red">
    <Button x:Name="btn1" BackgroundColor="White" Image="@drawable/scan" />
    <Button x:Name="btn2" BackgroundColor="White" Image="@drawable/menu" />
    <Button x:Name="btn3" BackgroundColor="White" Image="@drawable/search" />
  </StackLayout>
  <StackLayout x:Name="layoutList" >
    <ListView  x:Name="listView" Rotation="270" RowHeight="75" >
      <ListView.ItemTemplate>
        <DataTemplate>
          <ViewCell>
            <StackLayout BackgroundColor="#eee" Orientation="Vertical" >
              <StackLayout Orientation="Horizontal" >
                <Button BackgroundColor="White" Rotation="90" Image="{Binding Recipe}" />
              </StackLayout>
          </StackLayout>
          </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>
  </StackLayout>
 </StackLayout>
 </ContentPage.Content>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

编辑 我也尝试了在列表视图中的网格。有同样的问题。

 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="Recipe.Pages.SearchPage"
         Title="Search">
<ContentPage.Content>
<StackLayout Spacing="5" x:Name="layout" …
Run Code Online (Sandbox Code Playgroud)

xaml listview horizontallist xamarin.forms

3
推荐指数
1
解决办法
2180
查看次数