LC6464.ASPNET.HttpConnectionInfo 1.0.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package LC6464.ASPNET.HttpConnectionInfo --version 1.0.0                
NuGet\Install-Package LC6464.ASPNET.HttpConnectionInfo -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LC6464.ASPNET.HttpConnectionInfo" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LC6464.ASPNET.HttpConnectionInfo --version 1.0.0                
#r "nuget: LC6464.ASPNET.HttpConnectionInfo, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LC6464.ASPNET.HttpConnectionInfo as a Cake Addin
#addin nuget:?package=LC6464.ASPNET.HttpConnectionInfo&version=1.0.0

// Install LC6464.ASPNET.HttpConnectionInfo as a Cake Tool
#tool nuget:?package=LC6464.ASPNET.HttpConnectionInfo&version=1.0.0                

LC6464.ASPNET.HttpConnectionInfo

NuGet 包

在 ASP.NET 中快速获取当前 HTTP 连接的信息。

使用方法

ExampleWebAPI.csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">
	<PropertyGroup>
		<TargetFramework>net6.0</TargetFramework>
		<Nullable>enable</Nullable>
		<ImplicitUsings>enable</ImplicitUsings>
		
	</PropertyGroup>
	<ItemGroup>
		<PackageReference Include="LC6464.ASPNET.HttpConnectionInfo" Version="1.0.0.0" />
		
	</ItemGroup>
	<ItemGroup>
		<Using Include="LC6464.ASPNET.HttpConnectionInfo" />
		
	</ItemGroup>
</Project>

Program.cs:

var builder = WebApplication.CreateBuilder(args); // 创建 builder


// -------- 添加一些服务 --------


builder.Services.AddHttpConnectionInfo(); // 添加 HttpConnectionInfo 服务


// -------- 添加另外一些服务、构建 WebApplication 等 --------

ExampleController.cs:

// -------- 一些 Using --------

namespace ExampleWebAPI.Controllers;
[ApiController]
[Route("[controller]")]
public class ExampleController : ControllerBase {
	private readonly ILogger<HelloController> _logger;
	private readonly IHttpConnectionInfo _info; // 接口

	public HelloController(ILogger<HelloController> logger, IHttpConnectionInfo info) { // 依赖注入
		_logger = logger;
		_info = info; // 赋值
	}

	[HttpGet]
	[ResponseCache(CacheProfileName = "NoCache")]
	public Hello Get() {
		var address = _info.RemoteAddress; // 获取接口的值
		_logger.LogDebug("Hello! Client {}:{} on {}", address?.AddressFamily == AddressFamily.InterNetworkV6 ? $"[{address}]" : address, _info.RemotePort, _info.Protocol);
		return new(_info);
	}
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on LC6464.ASPNET.HttpConnectionInfo:

Package Downloads
LC6464.ASPNET.Http304

在 ASP.NET 中用于快速获取设置 HTTP 304 状态码的服务。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 647 1/1/2023
1.0.1 424 7/10/2022
1.0.0 336 7/10/2022

初步实现功能。