如何检索此asp.NET web api方法中的Ajax标头? [英] How to retrieve Ajax header in this asp.NET web api method?

查看:106
本文介绍了如何检索此asp.NET web api方法中的Ajax标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    [Route("api/test")]
    public IEnumerable<Tests> GetTests()
    {
         //Retrieve ajax header here?? 
        return ClassTestfuntions.Testmethod();     
    }

我有这个用于获取列表的asp.net web api方法从我的数据库的行,即时通讯现在也发送一个头到我的ajax HTTP调用这个方法,但我不知道如何检索它的价值,任何帮助或输入高度赞赏,谢谢!

I have this asp.net web api method that i use to GET a list of rows from my db, im now also sending an header to this method within my ajax http get call but im not sure how to retrieve it's value, any help or input highly appreciated, thanks!

推荐答案

您可以从请求标头中获取它,如下所示:

You can pull it from the request headers as follows:

var headers = Request.Headers.GetValues("AjaxHeader");
var ajaxHeader = headers.FirstOrDefault();

这篇关于如何检索此asp.NET web api方法中的Ajax标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆