C# 从不扩展System.Web.UI.Page的类获取System.Web.HttpResponse
虽然标题说明了一切,但我想让你知道我需要这个的特定场景 在应用程序中,我想通过调用JavaScript方法注销用户。此方法依次调用WebMethod:C# 从不扩展System.Web.UI.Page的类获取System.Web.HttpResponse,c#,asp.net,authentication,response,webmethod,C#,Asp.net,Authentication,Response,Webmethod,虽然标题说明了一切,但我想让你知道我需要这个的特定场景 在应用程序中,我想通过调用JavaScript方法注销用户。此方法依次调用WebMethod: namespace EMSApplication.Web.WebServices { /// <summary> /// Holds the Webservice methods of EMSApplication /// </summary> [WebService(Namespace =
namespace EMSApplication.Web.WebServices {
/// <summary>
/// Holds the Webservice methods of EMSApplication
/// </summary>
[WebService(Namespace = "http://ems-app.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class EMSWebService : System.Web.Services.WebService {
[WebMethod]
public string Logout() {
if (User.Identity.IsAuthenticated) {
System.Diagnostics.Debug.WriteLine(" ==JYM00000000000000000000000000000");
FormsAuthentication.SignOut();
Response.Redirect("~/default.aspx");
}
return "";
}
}
}
名称空间EMSApplication.Web.WebServices{
///
///保存EMSApplication的Web服务方法
///
[WebService(命名空间=”http://ems-app.com/")]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
公共类EMSWebService:System.Web.Services.WebService{
[网络方法]
公共字符串注销(){
if(User.Identity.IsAuthenticated){
System.Diagnostics.Debug.WriteLine(==jym00000000000000000);
FormsAuthentication.SignOut();
Response.Redirect(“~/default.aspx”);
}
返回“”;
}
}
}
我怎样才能解决这个问题
HttpContext.Current.Response
这是一个静态属性
这是一个静态属性。响应。重定向将创建302 Http响应,这对于浏览器意味着需要将用户重定向到新位置 由于现在调用是从javascript发出的,javascript需要解释响应并指示浏览器加载新位置 我现在想到的最简单的方法是Logout()方法返回新位置,JavaScript将设置window.location属性
window.location = msg.d;
通过Web服务,您可以从HttpContext类(
HttpContext.Current.Response.Redirect()
)访问响应,但您不需要它。事实上,我不认为Web服务应该编写比普通响应(SOAP等)更多的响应。响应。重定向将创建302 Http响应,这对于浏览器意味着需要将用户重定向到新位置
由于现在调用是从javascript发出的,javascript需要解释响应并指示浏览器加载新位置
我现在想到的最简单的方法是Logout()方法返回新位置,JavaScript将设置window.location属性
window.location = msg.d;
通过Web服务,您可以从HttpContext类(HttpContext.Current.Response.Redirect()
)访问响应,但您不需要它。事实上,我不认为Web服务应该编写比通常的响应(SOAP等)更多的响应