我想要做的是链接和ASP应用程序与MVC应用程序。现在,MVC应用程序包含在我的ASP应用程序框架中。我想要做的是当我点击我的ASP应用程序的注销按钮时,MVC应用程序的注销方法也被调用。响应重定向vs http请求获取响应
现在我注销页面看起来像这样:
<% Dim xmlhttp, cookie
'xmlHttp makes and async call to a POST method which finishes the ASP application session
Session.Abandon
'I execute methods to set the cookie value to an empty string
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Logout</title>
</head>
<body onload="document.forms[0].submit();">
<form method="POST" action="/end_MVC_Application.aspx">
<input type="submit" style="display:none" />
</form>
</body>
</html>
的end_MVC_Application页面居然是空的:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="end_MVC_Application.aspx.cs" Inherits="end_MVC_Application" %>
但后面的代码具有以下逻辑。我在这里做的是通过重定向页面以调用注销MVC特定方法来调用该方法来注销MVC应用程序。请注意,Logout方法不会返回MVC上的视图,因为我不需要它。
protected void Page_Load(object sender, EventArgs e)
{
string url = "http:localhost/MyController/Logout";
Response.Redirect(url,true);
}
这很好,MVC应用程序实际上是注销。不过,我需要重定向到ASP应用程序的实际登录页面。我尝试过不同的方式,但似乎没有任何工作。我试图在现有方法的Response.Redirect的改成这样:
protected void Page_Load(object sender, EventArgs e)
{
string url = "http:localhost/MyController/Logout";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Response.Write("<script>");
Response.Write("window.open('http://localhost/login.asp" + "', '_top')");
Response.Write("</script>");
}
这样,我已经验证,在MVC应用程序注销方法被调用,并且应用程序被重定向到登录页面。但是,即使正在调用注销方法,也不会关闭MVC应用程序。 我不明白为什么Response.Redirect的行为不同。我猜测它与结束响应的“真正的”布尔值有关,但我不明白。
如果你能帮助我,我将不胜感激。问候,路易斯。