Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7766459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:25:23+00:00 2026-06-01T15:25:23+00:00

I have a blog post page with comments. Any user (logged in or not)

  • 0

I have a blog post page with comments.
Any user (logged in or not) can see a form at the bottom of the page to post a comment.
When user enters the comment and she is not authorized – the user is redirected to a login/signup page.
After logged in, the user is redirected back to the action, but the POST data, containing the comment body, is lost.

I use the ASP.NET MVC Authorize attribute to require authorization on some actions:

[AcceptVerbs(HttpVerbs.Post), Authorize]
public ActionResult Create(int blogPostID, string commentBody) {
    var comment = new Comment {
       Body = commentBody,
       BlogPostID = blogPostID,
       UserName = User.Identity.Name
    }
    // persist the comment and redirect to a blog post page with recently added comment
}

How do you solve this problem?

Making user loggin before displaying the comment form is a bad idea here I think.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:25:25+00:00Added an answer on June 1, 2026 at 3:25 pm

    I would probably just save off the siteId and comment into the Session. Then create another overload for Create that doesn’t take any parameters. It checks to see if these variables exist in the session – if so, pass it off to your original Create method.

    To do that, you’d have to remove the Authorize attribute and just do the security check yourself. Something like this:

    var user = HttpContext.User;
    
    if (!user.Identity.IsAuthenticated)
    { 
       Session["Comment"] = comment;
       Session["SiteId"] = siteId;
       return RedirectToAction("LogOn", "Account", 
                               new { returnUrl = "/ControllerName/Create"} );
    }
    

    Then your overloaded Create:

    public ActionResult Create()
    {
        var comment = (Session["Comment"] ?? "").ToString();
        int siteId = 0;
        if (Session["siteId"] != null)
            siteId = (int)Session["siteId"];
    
        return Create(siteId, comment);
    }
    

    Of course, this isn’t really all that generic and doesn’t handle more complex scenarios, but it’s an idea. (hopefully the above code works, I haven’t had a chance to test it). It seems like you could maybe do something like this via an action filter but I don’t have any sample code for that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a blog where people can post their comments. My problem is that
I have a blog site with all the blog stuff including a post page
I have a blog on something.wordpress.com , I simply want one post to ALWAYS
like in this post here by exemple I have found this blog but in
I have problem on my blog: http://osify.com while processing add new post with above
I have a discussion forum/blog engine working with web forms. Each post contains html
I have a blog that has a redirect loop, and I can't understand htaccess
I have a blog. On my index page, I pull in all blog posts.
I have a blog.Few articles inside.Per each article I have a lot of comments
Let's say you have this scenario:a simple blog home-page that loads both static content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.