More control on ASP.Net MVC's Authorize; to keep AJAX requests AJAXy

前端 未结 4 1669
深忆病人
深忆病人 2020-12-28 11:17

I have some action methods behind an Authorize like:

[AcceptVerbs(HttpVerbs.Post), Authorize]
public ActionResult Create(int siteId, Comment comment) {
         


        
4条回答
  •  抹茶落季
    2020-12-28 11:42

    I think the right way to handle this would be in your Javascript making the AJAX call.

    If the user needs to be authorized (or authenticated as your code implies) and isn't, you should inform them and maybe not allow them to try and comment in the first place.

    However, if that doesn't suit your needs. You could try and write your own authorize action filter, maybe inheriting from the one that comes with the MVC framework but redirects how you want it to. It's fairly straightforward.

提交回复
热议问题