2016-12-21 106 views
0

的查询字符串参数我无法从网址,以获取查询参数在asp.net无法获得在asp.net

网址是:here

我的代码是

string code = Request.QueryString["code"]; 
    string clientid = Request.QueryString["client_id"]; 

我得到的代码参数,但client_id为空。我在这里做错了。

+0

他们将代码中的值分配给response_type.so代码= response_type –

+3

是不是后退了..?我的意思是,'key = value'。 '... WebForm2.aspx&response_type = code&client ...''很明显''response_type = code'通常会说话,你的'locahost:14772'是'redirect_uri'的值,所以把它作为查询字符串会有点棘手。 –

+0

嗨@BagusTesa不,它是一个动态生成的URL合成者 –

回答

0
you are use like, 

string code = Request.QueryString["response_type"]; 
    string clientid = Request.QueryString["client_id"]; 

你在string code = Request.QueryString["response_type"]; 检错与此请。

+0

我试过但没有结果。 –

+0

它说什么?返回null啊? –

+0

是yar。你能以另一种方式给我建议吗? –

0

重定向URL不正确,因此重定向过程中redirect_uri编码从谷歌的查询字符串参数第一&之后将被忽略(REDIRECT_URI不应包含&,因为它是你必须保持它的编码形式%26)。

的初始URL是(包含 'CLIENT_ID'):

https://accounts.google.com/o/oauth2/auth?scope=profile%20email&state=%2Fprofile&redirect_uri=http://localhost:14772/WebForm2.aspx&response_type=code&client_id = 41866849709-lobbqne5v4asm7dn2fu1v8lubm6pc7e7.apps.googleusercontent.com & approval_prompt =由重定向力

但经过谷歌其不有Client_Id。

http://localhost:14772/WebForm2.aspx?state=/profile&code=4/gh9Yl3D5Nn220V3nU8d8E5vzC4SmEP6JncnGa6MrgSs#

的问题是redirect_uri内容的编码不正确。请正确配置。它应该看起来像:

的http%3A%2F%2Flocalhost%3A14772%2FWebForm2.aspx%26response_type%3Dcode%26client_id%3D41866849709-lobbqne5v4asm7dn2fu1v8lubm6pc7e7.apps.googleusercontent.com%26approval_prompt%3Dforce