我繼承了一個相當複雜的項目。原始設計師創建了一個「cookie」,似乎是服務器端而不是基於客戶端(儘管我可能在該部分非常錯誤)。他將它用於他所謂的「最低特權,單一登錄」。我有下面的代碼在所有的Web服務代理的他成立了:服務器Cookie?
[WebServiceBinding(Name = "ISecurityManager", Namespace = "urn:riv:apis:security:forms:ver1")]
public partial class SecurityManager : SoapHttpClientProtocol, ISecurityManager
{
public SecurityManager()
{
//Url = CookieManager.WebServiceUrl(String.Empty, ref CookieContainer);
// I’d like to replace the following code with a call like this...
CookieContainer = new System.Net.CookieContainer();
string urlSetting = ConfigurationManager.AppSettings["SecurityManager"];
if (urlSetting != null)
Url = urlSetting;
else
Trace.TraceWarning("No URL was found in application configuration file");
string cookieName = FormsAuthentication.FormsCookieName;
string cookiePath = FormsAuthentication.FormsCookiePath;
string cookieDomain = Properties.Settings.Default.CookieDomain;
HttpCookie authCookie = HttpContext.Current.Request.Cookies[cookieName];
if (null != authCookie)
CookieContainer.Add(new Uri(urlSetting), new System.Net.Cookie(cookieName, authCookie.Value, cookiePath, cookieDomain));
}
….
我也有這樣的代碼非常到處:
string cookieName = FormsAuthentication.FormsCookieName;
string SecurityContext.ApplicationName = HttpContext.Current.Request.Cookies[cookieName].Path;
string SecurityContext.UserName = HttpContext.Current.User.Identity.Name;
if (!string.IsNullOrEmpty(SecurityContext.UserName))
….
在所有情況下,當它獲得authCookie,它出現null或SecurityContext.UserName爲空。我不是一個cookie大師,這個人的代碼很多都是混淆的 - 而且文檔也是零。
任何人都可以使頭或尾出於代碼塊的意圖嗎?
TIA