【发布时间】:2014-09-18 22:38:18
【问题描述】:
我想要做的是将 ASP 应用程序与 MVC 应用程序链接起来。现在 MVC 应用程序包含在我的 ASP 应用程序的框架中。我想要做的是,当我单击 ASP 应用程序的注销按钮时,也会调用 MVC 应用程序的注销方法。
现在我的登出页面是这样的:
<% 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 行为不同。我猜它与结束响应的“真实”布尔值有关,但我不明白。
如果您能帮我解决这个问题,我将不胜感激。问候,路易斯。
【问题讨论】:
标签: c# asp.net asp.net-mvc redirect