0
我有系統A的內部下面的操作方法,它調用使用Web客戶端的系統B另一個操作方法: -得到它調用一個動作方法的服務器的IP地址
public async Task<ActionResult> Scan()
{
try
{
string currentURL = System.Web.Configuration.WebConfigurationManager.AppSettings["scanningURL"];
using (WebClient wc = new WebClient())
{
string url = currentURL + "home/scanserver?tokenfromtms=" + "*****" + "&FQDN=allscan" ;
var json = await wc.DownloadStringTaskAsync(url);
TempData["messagePartial"] = string.Format("Scan has been completed. Scan reported generated");
}
}
和內部系統的操作方法B,將利用上面的活動方法被調用爲: -
public async Task<ActionResult> ScanServer(string tokenf, string FQDN)
{
string Token = System.Web.Configuration.WebConfigurationManager.AppSettings["Token"];//get the token from the web.config, this should be encrypted
if (tokenf != Token || Request.UserHostAddress != System.Web.Configuration.WebConfigurationManager.AppSettings["CallingIP"])
現在我所要做的,就是內部系統B檢查是否正被提交的請求是從系統A的IP地址。所以在系統B上使用Request.UserHostAddress
的操作方法會給我係統的IP地址,它調用它的操作方法(系統A在我的情況下?)
所以你的意思是我目前的做法不行? –
這可能會起作用,你可以訪問httpContext並且可以讀取web.config密鑰,但是如果你打算根據這些信息拒絕請求,那麼最好不要進入控制器來做這件事。您可以在請求管道的更早步驟執行此操作。 – Brduca