【发布时间】:2019-03-08 15:32:01
【问题描述】:
我正在尝试将一个对象从后面的 aspx 代码传递到 Web 应用程序 angularjs 控制器。让我解释一下这个问题。
我有一个名为 app1 的 aspx 应用程序,此应用程序会登录并返回一个大的复杂对象(json 或模型)。
我也有一个名为 app2 的 angularjs 应用程序,该应用程序必须接收复杂对象以映射并填充身份验证 angular 变量。
App1 和 App2 在同一个表示层中。
我的问题是,如何将复杂对象从 aspx 应用程序传递到 angularjs 控制器。
//Do login from aspx appplication (app1)
protected void submit_Click(object sender, EventArgs e)
{
lblResponse.Text = "";
string requestStr = null;
string responseStr = null;
var request = new RestRequest("signin", Method.POST);
SignInRequestREST signinRequest = new SignInRequestREST();
signinRequest.Mail = txtMail.Text;
signinRequest.Password = txtPassword.Text;
signinRequest.SupplierLogin = true;
request.AddJsonBody(signinRequest);
requestStr = request.JsonSerializer.Serialize(signinRequest);
HttpStatusCode status = HttpStatusCode.OK;
IRestResponse response = Execute(request, out status, ConfigurationManager.AppSettings["URL"]);
responseStr = response.Content; //Here it's my object in json encode
if (status == HttpStatusCode.OK)
{
lblResponse.Text = "Is authenticated";
//Now, here it's my problem
//How can pass responseStr to app2?
}
else
{
lblResponse.Text = "It's not authenticated";
}
}
//AngularJS controller app2)
$scope.Init = function () {
//$scope.userInStorage = SessionStorage.getUser('User');
$scope.userInStorage = responseStr;
//but I don't know how catch responseStr here?
}
通常,您可以从 Angular 发出 http 请求,然后捕获响应。
在这种情况下,aspx 必须执行请求,而 angular 必须仅捕获响应。
有什么想法吗?非常感谢帮助。
【问题讨论】: