我一直在我的Web表單代碼隱藏類中使用以下代碼。我想在我的常規.cs文件中使用它:例如,在進行數據庫調用時。但是,當我試圖在Web表單外部使用它時,在嘗試映射base.Request.ApplicationPath時出現以下錯誤:'object'不包含'Request'的定義。映射到Web應用程序項目中的常規.cs類文件中的根的簡單而正確的方法是什麼?如何在ASP.NET非表格類文件中映射路徑
protected void LogError(string errMsg, string errTrace)
{
string mailSubject = "oops!";
string mailBody = errMsg + errTrace;
System.Configuration.Configuration config
= WebConfigurationManager.OpenWebConfiguration(base.Request.ApplicationPath);
AppSettingsSection appSettings = (AppSettingsSection)config.GetSection("appSettings");
// Extract values from the web.config file
string toAddress = "[email protected]";
string fromAddress = appSettings.Settings["FromEmailAddr"].Value;
string emailHost = appSettings.Settings["EmailHost"].Value;
mailProvider.SendMail(fromAddress, toAddress, mailSubject, mailBody.ToString());
}
這是一個很酷的gravatar!感謝您的解決方案,約翰剛剛在你的帖子:-) – IrishChieftain 2009-05-29 13:38:19