title: MVC - Tweet from Controller not working well
body: <p>I have a problem with Twitter tweet from my application, I don't understand why not working.</p>
  
  <p>This is my code:</p>
  
  <pre><code>TwitterHelper.Tweet(Message, Request,
       unitOfWork.UserProfileRepository.GetByID(WebSecurity.CurrentUserId).ToString());
  </code></pre>
  
  <p>If I use my code from the Controller's <code>ActionResult Index...</code> method or from Edit method, working fine.</p>
  
  <p>But If I use from my own </p>
  
  <pre><code>ActionResult SendTweet(string message) 
  {
      ...
  </code></pre>
  
  <p>it is not working. No error message, just not reaching the twitter, don't want to authenticate, etc. </p>
  
  <p>I call this method from my view with ajax</p>
  
  <pre><code>$.ajax({
      url: "/MyController/SendTweet",
      type: "POST",
      dataType: "json",
      data: { Message: $('#Message').val()},
      success: function (data) { $('#Message').text = ''; }
  });
  </code></pre>
  
  <p>If i debug my controller I have the Message value and going through the call and no exception, but not working.</p>
  
  <p><strong>Update</strong>
  The Request parameter is used after the Twitter authentication. What is happening: If i call from Index for example: </p>
  
  <pre><code>if(userName != TwitterHelper._userName) 
  { 
      TwitterHelper._userName = userName; 
      TwitterHelper._accessToken = null;  
      TwitterHelper._accessTokenSecret = null; 
      TwitterHelper._userId = null; 
      TwitterHelper._screenName = null; 
  }
  </code></pre>
  
  <p>after that: </p>
  
  <pre><code>SortedDictionary&lt;string, string&gt; requestTokenParams = 
      new SortedDictionary&lt;string, string&gt;(); 
  
  requestTokenParams.Add("oauth_callback", HttpContext.Current.Request.Url.AbsoluteUri); 
  
  var tokenResponse = 
      TwitterHelper.GetToken("api.twitter.com/oauth/request_token";, requestTokenParams); 
  
  NameValueCollection qscoll = HttpUtility.ParseQueryString(tokenResponse); 
  
  var loginUrl = "api.twitter.com/oauth/authenticate?oauth_token="; 
      + qscoll["oauth_token"];
  </code></pre>
  
  <p>and: </p>
  
  <pre><code>//(HERE THE BROWSER SHOWS THE TWITTER LOGIN) –
  HttpContext.Current.Response.Redirect(loginUrl);   
  </code></pre>
  
  <p>If I call Tweet from the SendTweet method the way is the same. But here: <code>HttpContext.Current.Response.Redirect(loginUrl);</code> not shows anything, no login page. nothing happenin</p>
  
  <p>Could you please help ?
  Thanks in advance.</p>