C# Webmethod没有';点击Angular2,结果显示整个页面html
我有一个简单的C# Webmethod没有';点击Angular2,结果显示整个页面html,c#,asp.net,angular,typescript,webmethod,C#,Asp.net,Angular,Typescript,Webmethod,我有一个简单的WebMethod,如下所示 [WebMethod(EnableSession=true)] public static string Redirect() { object a= HttpContext.Current.Session; return "yeppieee"; } 并称之为 this.http.get(`http://localhost/MyApp/Pages/TestPage.aspx/Redirect`) .map(res=&g
WebMethod
,如下所示
[WebMethod(EnableSession=true)]
public static string Redirect()
{
object a= HttpContext.Current.Session;
return "yeppieee";
}
并称之为
this.http.get(`http://localhost/MyApp/Pages/TestPage.aspx/Redirect`)
.map(res=>res)
.subscribe((res) =>{
console.log(res);
},
(err)=>console.log(err),
()=>console.log("Done1111111111")
);
但调试器并没有运行
在控制台上,我可以看到done1111111
。
在开发者工具的网络选项卡中,我可以看到此请求的状态为200
,即OK
那么为什么没有调用WebMethod
编辑
刚知道响应是整个html页面。我可以在控制台中看到这一点。好的,我设法解决了这个问题。当它返回整个页面html时,我只是将内容类型添加为json到请求头中,如下所示
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
this.http.get(`http://localhost/HelixWebApp/Pages/AngularContainer.aspx/Redirect`, options)
.map(res=>res.json())
.subscribe((res) =>{
console.log(res);
},
(err)=>console.log(err),
()=>console.log("Done")
);
还将WebMethod
更改为接受GET
[WebMethod(EnableSession=true)]
[ScriptMethod(UseHttpGet = true)]
public static string Redirect()
{
object a= HttpContext.Current.Session;
return "yeppieee";
}
好的,我设法解决了这个问题。当它返回整个页面html时,我只是将内容类型添加为json到请求头中,如下所示
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
this.http.get(`http://localhost/HelixWebApp/Pages/AngularContainer.aspx/Redirect`, options)
.map(res=>res.json())
.subscribe((res) =>{
console.log(res);
},
(err)=>console.log(err),
()=>console.log("Done")
);
还将WebMethod
更改为接受GET
[WebMethod(EnableSession=true)]
[ScriptMethod(UseHttpGet = true)]
public static string Redirect()
{
object a= HttpContext.Current.Session;
return "yeppieee";
}
将pst请求设置为此Web服务器。使用$http。Post@SURJEETSINGHBisht我没有发布任何内容。请将pst请求设置为此网站。使用$http。Post@SURJEETSINGHBisht我没有发布任何东西。