我对asp.net很新。我正在一个现有项目上构建,其中js文件中的用户名和密码被加密,并且对.aspx.cs文件进行了ajax函数调用。此ashx.cs文件解密它们,然后将它们插入到数据库表中。现在我想要包含一个名为" Domain"但我不知道如何为它创建一个标题,将它从js传递到ashx.cs文件。我的问题可能是愚蠢的,但我一直在努力与它一段时间,并感谢一些帮助。我尝试使用context.Response.AddHeader为域,但我不知道我应该传递给它的值..
" RUN"和" RUP"似乎已经在某处创建了,我无法找到它们以跟随域标题的相同...
js file:
function Register() {
if (ValidateRegisterWindow()) {
var URL = "SecureChatServer.ashx";
if (URL == null) { alert("Request URL is Empty"); }
else {
username = Encrypt(document.getElementById('NewUserName').value, EncryptionKey);
password = Encrypt(document.getElementById('NewPassword').value, EncryptionKey);
domain = Encrypt(document.getElementById('NewDomain').value, EncryptionKey);
AjaxRequest(ProcessRegisterResponse, URL, "POST", '', '', { RequestCode: 'SC006', RUN: username, RUP: password}); //how to pass domain here??
}
}
}
function ProcessRegisterResponse() {
var ResponseStatus = GetHeader(ResponseHeaderJSON, 'ResponseStatus');
if (ResponseStatus == "RS-OK") {
ShowAlertMessage("Registration Sucessful", "", "User Registered and Logged in Sucessfully");
CurrentUser = document.getElementById('NewUserName').value;
LoginEvents(CurrentUser, true);
ClearRegisterWindow();
}
else if (ResponseStatus == "RS-Failed") {
ShowErrorBox("Registration Error", "This username cannot be registered ,please try a different username");
}
else {
ShowErrorBox("Unknown Error :Code-01 " + ResponseStatus, "Request cannot be processed ,please try again.");
}
}
ashx.cs文件:
#region Handle Add New User Request
case "SC006": //indicates request to add new user
{
string UserName, Password;
UserName = Decrypt(context.Request.Headers["RUN"], EncryptionKey);
Password = Decrypt(context.Request.Headers["RUP"], EncryptionKey);
Users newuser = new Users();
try
{
if (newuser.AddUser(UserName, Password, SessionID, UserIPAddress))
{
context.Response.AddHeader("CustomHeaderJSON", "ResponseStatus:'RS-OK'");
}
else
{
context.Response.AddHeader("CustomHeaderJSON", "ResponseStatus:'RS-Failed'");
}
}
catch (Exception e)
{
Debug.WriteLine("Failed Request SC006 : " + e.ToString());
context.Response.AddHeader("CustomHeaderJSON", "ResponseStatus:'RS-Exception'");
}
}
break;
#endregion
答案 0 :(得分:1)
它很容易使用此代码添加标题
context.Response.Headers.Add(“你的标题在这里”);