---
sidebar_position: 6
slug: /dev/sforward
---

# 98.6、内网穿透验证

:::tip[说明]
验证通过则允许添加内网穿透
```
//初始化
LinkerMessengerEntry.Initialize();
//在这里注入
LinkerMessengerEntry.AddService<MySForwardValidator>();

//构建
LinkerMessengerEntry.Build();

SForwardValidatorTransfer sForwardValidatorTransfer 
= LinkerMessengerEntry.GetService<SForwardValidatorTransfer>();
//可以删除默认的一些验证,default默认的
//sForwardValidatorTransfer.RemoveValidators(new List<string>{ "default"});

ICommonStore commonStore = LinkerMessengerEntry.GetService<ICommonStore>();
//服务端则添加
if((commonStore.Modes & CommonModes.Server) == CommonModes.Server)
{
    sForwardValidatorTransfer.AddValidators(new List<ISForwardValidator> { 
        LinkerMessengerEntry.GetService<MySForwardValidator>() 
    });
}

//运行
LinkerMessengerEntry.Setup();


public sealed class MySForwardValidator : ISForwardValidator
{
    public string Name => "mySForwardValidator";
   
    /// <summary>
    /// 验证
    /// </summary>
    /// <param name="signCacheInfo">来源客户端</param>
    /// <param name="sForwardAddInfo">穿透信息</param>
    /// <returns>返回不为空则为错误信息，添加失败</returns>
    public async Task<string> Validate(SignCacheInfo signCacheInfo, SForwardAddInfo sForwardAddInfo)
    {
        await Task.CompletedTask;
        return string.Empty;
    }
}
```
:::