Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Dear Friends,

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

C#
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();

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

Thanks in Advance.
Gittu
Posted
Comments
[no name] 19-Oct-12 8:58am    
Is MSDN broken again? Have you notified Microsoft?
P_Dash 19-Oct-12 9:14am    
Sorry I'm not getting if there is any link of this with MSDN !!!
I.explore.code 19-Oct-12 9:21am    
apparently that will help you understand how to create an instance with inline initialisation of properties? if not then perhaps you need to ask specific question than "I'm not getting the 3rd line of this code".
P_Dash 19-Oct-12 10:23am    
Bro Particularly in 3rd Line what is the use of "{ Query = "" }", this statement ???
[no name] 19-Oct-12 9:30am    
You are joking right? www.msdn.microsoft.com

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 = "";


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 "".

[Edit]
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.
 
Share this answer
 
v4
Comments
P_Dash 21-Oct-12 2:11am    
Thank U Very Much Sir.

Well could u plz Tell Me if I remove the line { Query = "" } or b.Query = ""; from the code, then will it Hamper my Code in any Means ??
Keith Barrow 21-Oct-12 5:17am    
Without seeing the rest of your code, it is hard to say. My guess is that whoever wrote this code wants to copy all the information from the request url, but needs to strip the query part out for some reason. This was probably done for a reason, so my guess is that the assignment is needed. The best thing to do is for you to trace through the code yourself and see what effect removing the assignment has
P_Dash 26-Oct-12 9:10am    
Sir, basically I'm using this for Open Authentication using GMail Authentication.
So now can u plz tell me if removing Query part will hamper my Result or Not ?
Keith Barrow 26-Oct-12 9:45am    
Hi, I've updated my answer. You need to remove the query string for the open ID request, see my answer for the reasons.
P_Dash 26-Oct-12 10:05am    
Well Sir, I'm getting perfect result without removing the Query String, means the code I've mentioned on the 1st thread is working perfectly fine.

So I think this is not a problem what u mentioned in ur Edited post.

I just want to know What's the Purpose of mentioning Query String, also if I mention Query String=<some value=""> then what will happen ??
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.
 
Share this answer
 
Comments
P_Dash 21-Oct-12 2:11am    
Thank U Very Much Sir.

Well could u plz Tell Me if I remove the line { Query = "" } from UriBuilder constructor, then will it Hamper my Code in any Means ??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900