我有一個功能可以創建語音郵件,並且如果通過Twitter進行身份驗證,則會向他們的Twitter帳戶發佈消息。我希望用戶可以根據需要關閉發送給Twitter的消息,所以我很好奇是否有辦法清除證書。我跟着從LinqToTwitter文檔的例子:Linq到Twitter清除IOAuthCredentials憑據
IOAuthCredentials credentials = new SessionStateCredentials();
if (credentials.ConsumerKey == null || credentials.ConsumerSecret == null)
{
credentials.ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"];
credentials.ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"];
}
auth = new WebAuthorizer
{
Credentials = credentials,
PerformRedirect = authUrl => Response.Redirect(authUrl)
};
if (!Page.IsPostBack && Request.QueryString["oauth_token"] != null)
{
auth.CompleteAuthorization(Request.Url);
}
if (auth.IsAuthorized)
{
twitterCtx = new TwitterContext(auth);
Session["TwitterContext"] = twitterCtx;
twLoginButton.Text = "Logout of Twitter";
}
我試過下面的代碼和變化:
credentials = null;
或
SessionStateCredentials credentials = Dispose();
但它顯示了每個的這些錯誤。我希望有人能指導我清除
IOAuthCredentials credentials = new SessionStateCredentials();
這是我認爲需要發生的事情。任何意見,將不勝感激。
我試圖清除後面的按鈕點擊代碼證書和所使用的Session.Remove理念。當我嘗試重新進行身份驗證時,會出現401錯誤。你能否通過獲得當前會議的參考來解釋你的意思?我很感激。 –
如果你的邏輯是在一個庫中,你需要添加一個項目引用System.Web.dll,爲System.Web添加一個using語句,並引用HttpContext.Current.Session屬性(就像我在答案鏈接)。由於您處於代碼隱藏狀態,如您所知,您可以說Session。401的原因是因爲你可能已經清除了ConsumerKey和ConsumerSecret。我不知道你在做什麼,所以我在回答中提到了這些。如果您想用相同的授權人重新進行身份驗證,請單獨保留ConsumerKey和ConsumerSecret,並僅清除OAuthToken和AccessToken。 –