ASP.NET MVC not rendering

I have the following

NewsFeedController.cs

public class NewsFeedController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult TwitterCallback(string oauth_token, string oauth_verifier)
    {
        var requestToken = new OAuthRequestToken { Token = oauth_token };

        string Key = "";
        string Secret = "";

        try
        {
            TwitterService service = new TwitterService(Key, Secret);

            OAuthAccessToken accessToken = service.GetAccessToken(requestToken, oauth_verifier);

            service.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);

            VerifyCredentialsOptions option = new VerifyCredentialsOptions();

            TwitterUser user = service.VerifyCredentials(option);
            String name = user.ScreenName;

            ViewData["user_name"] = name;
        }
        catch
        {
            throw;
        }
        return View();
    }
}

      

with the following

TwitterCallback.cshtml

@{
    ViewData["Title"] = "TwitterCallback";
}

<h2>Hello, @ViewData["user_name"]</h2>

      

RouteConfig.cs

 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

 routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

      

My problem is that NewsFeedController

it doesn't display anything. It executes TwitterCallback

without throwing exceptions but returns no view. If I change the type of the method to String and return the ViewData["user_name"]

correct name is displayed. Therefore, I think that I somehow proclaimed the point of view in the wrong way.

I just started chatting with mvc, so I apologize if this might sound like a beginner's question.

Any help / advice would be greatly appreciated!

Project structure:

Project structure

This is what I get: (no error message, nothing)

enter image description here

EDIT: This is how the callback url is called: (where TwitterAuth is a method in HomeController.cs and is called when the user clicks the login button)

public ActionResult TwitterAuth()
        {
            string Key = "";
            string Secret = "";

            TwitterService service = new TwitterService(Key, Secret);

            OAuthRequestToken requestToken = service.GetRequestToken("http://127.0.0.1:8080/NewsFeed/TwitterCallback");

            Uri uri = service.GetAuthenticationUrl(requestToken);

            return Redirect(uri.ToString());
        } 

      

If I just paste the redirect url into my browser, I get this: enter image description here

EDIT2: Thanks everyone for your help. I still don't understand why it didn't work in the first place (as Andrew said in the comments, this is not a .net issue). I changed my twitter library to tweetinvi and now it works.

+3


source to share





All Articles