我希望某些restful操作需要认证,可asp.net 的认证注解不好用:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "foo",
LoginPath = new PathString("/user/forbidden"),
AccessDeniedPath = new PathString("/user/forbidden"),
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
我的控制器需要返回json数据,加了[Authorize]的部分如果没登陆的话AccessDeniedPath 好像从来不会跳到,然后我把LoginPath也改成一样,倒是返回json数据了,可url也跳转了,还携带了return url信息.我的需求是加[Authorize]的控制器代码只返回{"error":"need anthorize"}就好,这应该怎么改动?
自己重写,下面是api的
/// <summary>