如何在公共类中使用HttpContext。我没有关于Cookies的所有方法,如果没有这个:
namespace TradingDaysFileChecker
{
class Program
{
static void Main(string[] args)
{
var startDate = new DateTime(2007, 04, 01);
var endDate = new DateTime(2016, 07, 25);
var dataFilePath = @"C:\Users\richa_000\Desktop\exporter\forex\fxcm\minute\";
var securityType = SecurityType.Forex;
var ticker = TickType.Trade;
var marketHoursDatabase = MarketHoursDatabase.FromDataFolder();
var market = Market.FXCM;
var symbol = Symbol.Create(ticker.ToString(), securityType, market);
var marketHoursDbEntry = marketHoursDatabase.GetEntry(symbol.ID.Market, symbol.Value, symbol.ID.SecurityType);
var exchange = new ForexExchange(marketHoursDbEntry.ExchangeHours);
var validTradingDays = new DateHandler(startDate, endDate, dataFilePath).IterateOverDateRange(exchange);
var forexSecuritiesFolders = Directory.GetDirectories(dataFilePath);
foreach (var validDay in validTradingDays)
{
foreach (var forexSecurity in forexSecuritiesFolders)
{
var securityName = new DirectoryInfo(forexSecurity).Name;
var formattedFolderName = validDay.ToString("yyyyMMdd") + "_quote"; // Checks folder name
var formattedFileName = validDay.ToString("yyyyMMdd") + securityName + "_minute_quote";
var dataFile = dataFilePath + securityName + @"\" + formattedFolderName + @"\" + formattedFileName;
if (!File.Exists(dataFile))
{
// Some logic round here
}
}
}
Console.ReadLine();
}
}
}
任何想法如何在公共类中使用HttpContext.Request?也许有人有不同的方式来获取饼干?
答案 0 :(得分:2)
你试过HttpContext.Current吗? 如果您正在使用ASP.NET,那么这应该是一种从代码中的任何位置访问当前上下文的方法。如果你不是,解决方案就更棘手了。
即
HttpCookie cookie = HttpContext.Current.Request.Cookies.Get("MyCookieGitApplication");