我正在关注RazorGenerator上的这篇文章,它说我必须添加对以下内容的引用:
System.Web.Helpers.dllSystem.Web.WebPages.dllSystem.Web.Razor.dll我唯一能看到的Add Reference就是System.Web.Razor,但我不知道其他的在哪里.
我想要的是在对跨域进行Ajax调用时保护我的开发人员密钥.在我直接进入网址并插入密钥之前.像这样
$.ajax({
url: "https://na.api.pvp.net/api/lol/na/v2.3/team/TEAM-ID?api_key=mykey",
type: "GET",
data: {},
success: function (json) {
console.log(json);
console.log(json[teamID].name);
console.log(json[teamID].fullId);
console.log(json[teamID].roster.ownerId);
console.log(json[teamID].tag);
},
error: function (error) {}
});
Run Code Online (Sandbox Code Playgroud)
这将给我以下对象,我可以轻松解析.

但是,如上所述,任何人都可以在此过程中轻松抓住我的钥匙.所以我决定将这个动作移动到我的Controller(是的,我知道这里不应该有业务逻辑,但它更安全,这是一个快速的过程).
所以我现在正在做的是运行我的Javascript,它调用Controller以获得Json返回.
使用Javascript
$.ajax({
url: "/Competitive/teamLookUp",
type: "POST",
data: "ID=" + teamID,
success: function (json) {
console.log(json);
},
error: function(error) {
}
});
Run Code Online (Sandbox Code Playgroud)
我的控制器接受了这个并尝试返回JSON.
[HttpPost]
public ActionResult teamLookUp(string ID)
{
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("https://na.api.pvp.net/api/lol/na/v2.3/team/" + ID + "?api_key=myKey");
myReq.ContentType = "application/json";
var response = (HttpWebResponse)myReq.GetResponse();
string text;
using (var sr = new StreamReader(response.GetResponseStream()))
{
text = …Run Code Online (Sandbox Code Playgroud)