我已经阅读了 Securing AJAX Requests via GUID 和 Securing an ajax request 。现在让我解释一下我的场景,下面是可能有助于解释主题的代码片段。
[WebMethod[EnableSession = True]
[ScriptMethod]
public static string CreateTitle(string strTitleName)
{
string strResult = "Custom jSon string";
if(Session["Authorized"] == "True" && !String.IsNullOrEmpty(strTitleName))
{
String strTitle = Server.HtmlEncode(strTitleName);
InsertRecordInDB(strTitle);
strResult = "Custom jSOn string" + EncryptMD5("record id");
}
return strResult;
}
下面是发送参数的 javascript 调用。btnCreateTitle_click 是按钮客户端的点击事件。txtTitle 是接受标题名称的文本框。验证器也在页面上创建以验证文本框。CreateTitle 是我使用 scriptmanager 调用的页面方法
function btnCreateTitle_Click(evnt){
if(Page.ClientValidate()){
if($get("txtTitle")){
PageMethods.CreateTitle($get("txtTitle").value,success,failure,context);
}}}
函数成功显示标题已创建的咆哮消息,并显示带有加密记录 ID 的链接作为查询字符串到 url 以查看创建的标题的详细信息。
现在最迫切的问题,
- 这足够安全吗?我错过了什么?
- 我怎样才能使这个过程更安全、更快?