JFR
JFR

Reputation: 25

Link to action if user is authenticated in ASP.NET MVC

I'm creating a shopping cart using google checkout api.

I what to submit the form of the hidden fields only if the user is autenticated to the site.

How can I force (or redirect to login) authentication before submitting the form to google checkout?

Upvotes: 1

Views: 90

Answers (2)

hunter
hunter

Reputation: 63512

decorating your action method with the [Authorize] attribute should do it

[Authorize]
public ActionResult Cart()
{
    ...
}    

[Authorize]
[HttpPost]
public ActionResult Cart(CartModel model)
{
    ...
}

by default the user will get kicked out to your Log In page if you've defined one

Upvotes: 3

frennky
frennky

Reputation: 13934

Something like this:

[HttpPost]
public ActionResult CheckOut(Cart cart)
{
    if (User.Identity.IsAuthenticated)
    {
        //go checkout
    }
    else
    {
        //redirect
    }
}

Upvotes: 0

Related Questions