请给我解释一下这个ASP.Net代码!!! [英] Plz Explain me this ASP.Net code !!!

查看:95
本文介绍了请给我解释一下这个ASP.Net代码!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我正在学习开放式身份验证和无法理解此代码.
有人请向我解释此代码:

Dear Friends,

I''m learning Open Authentication & is unable to understand this code.
Someone Plz Explain me this code:

string discoveryUri = "https://www.google.com/accounts/o8/id";
OpenIdRelyingParty openid = new OpenIdRelyingParty();
var b = new UriBuilder(Request.Url) { Query = "" };
var req = openid.CreateRequest(discoveryUri, b.Uri, b.Uri);
req.RedirectToProvider();


特别是我没有得到这段代码的第三行.
有人请在这里帮我.

在此先感谢.
Gittu


Especially I''m not getting the 3rd line of this code.
Someone Plz Help me here.

Thanks in Advance.
Gittu

推荐答案

var b = new UriBuilder(Request.Url) { Query = "" };



只需使用一些语法糖,就可以将其重写.



Just employs some of syntactic sugar, it can be re-written.

UriBuilder b = new UriBuilder(Request.Url);
b.Query = "";



var关键字替换声明中的类型名称,由编译器在编译时确定.

{ Query = "" }b.Query属性设置为".


回应OP的评论

哇,我误读了您代码的前半部分.答案是保持查询字符串很可能会引起问题. openid.CreateRequest(discoveryUri, b.Uri, b.Uri);中的第二个参数需要为"描述您的Wesites地址的最短网址 [ ^ ].这可能无法包含查询字符串.另外,有可能您传递的字符串不够短,因为Open Auth对象期望的是 www.foo.com ,而不是<例如,i> www.foo.com/bar .令人怀疑的是,第三个参数中是否也应该包含查询字符串,但这取决于您在成功进行身份验证后期望进入您的网站的页面:-您需要进行检查.



The var keyword replaces the type name in the declaration, it is worked out by the compiler at compile time.

{ Query = "" } sets the b.Query property to "".


In response to the OP''s comment

Wow I misread the earlier part of your code. The answer is keeping the query string will very probably cause problems. The second parameter in openid.CreateRequest(discoveryUri, b.Uri, b.Uri); needs to be "the shortest url that describes your wesites address[^]". This can''t possibly contain the query string. Also, it is possible that the string you are passing is not short enough as the Open Auth object expects www.foo.com, not www.foo.com/bar for example. It is doubtful that the third parameter should have the query string either, but this depends on what the page you land on in your site after successful authentication expects:- you''d need to check this.


我将解释一些与第三行有关的术语,以便您可以了解Google进行进一步研究的内容.

首先,您有"var"关键字,该关键字用于创建一个其类型由编译器推断的变量.它仍然是强类型的,但是您不必显式地编写类型.

接下来,您使用"new"关键字创建变量的实例,在本例中为新的 UriBuilder .

在UriBuilder的右侧,您会看到一些paren及其之间的参数.这就是所谓的构造函数.使用此构造函数,您将传入一个URL,以用作创建UriBuilder的基础.在这种情况下传递的URL是当前请求的URL.

最后,您有一个对象初始化程序,它将在构造函数运行后在变量上设置属性.在这种情况下设置的属性是查询字符串.
I''ll explain a few terms relating to the third line so that you can know what to Google to do further research.

First of all, you have the "var" keyword, which is used to create a variable that has its type inferred by the compiler. It is still strongly typed, but you don''t have to explicitly write the type.

Next, you are using the "new" keyword to create an instance of a variable, in this case a new UriBuilder.

To the right of the UriBuilder, you see some parens with a parameter in between them. That is called a constructor. With this constructor, you are passing in a URL to use as the basis for creating your UriBuilder. The URL passed in this case is the URL of the current request.

Finally, you have an object initializer, which will set properties on the variable after the constructor is run. The property that is set in this case is the query string.


这篇关于请给我解释一下这个ASP.Net代码!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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