In ASP.NET Core, if we use jQuery Ajax to post data to the server, and we want the ValidateAntiForgeryToken attribute to work. We have to do some tricks. The official document didn't document how to do it via jQuery. Let me show you how to do it. Please do read the official document first: https://docs.microsoft.com/en-us/aspnet/core/security/anti-request-forgery?view=aspnetcore-2.1 In my …
这几天在研究JQuery和WebService,被泛型返回类型搞死了。查了很多资料做实验终于搞定了。网上很多垃圾文章的作者都不亲手实验就到处拼凑把东西发上来,太不负责了。下面我发的是100%可用的,经过亲手实验的代码。 首先在WebService上要注意一点,一定记得把[System.Web.Script.Services.ScriptService]这行取消注释,这样脚本才可以调用到WebService。如图: 我用来测试的是我网站的友情链接列表,其WebService方法如下: [WebMethod] public List GetFriendLinks() { return new EdiBlog.Core.FriendLink().GetModelList(); } 经过测试,在浏览器中用GET访问是会爆掉的,所以我们用POST方法去调用。在默认的IIS和ASP. …