开发者

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 fiel开发者_运维问答ds 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?


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


Something like this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜