Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Webmethod没有';点击Angular2,结果显示整个页面html_C#_Asp.net_Angular_Typescript_Webmethod - Fatal编程技术网

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我没有发布任何东西。