Sunday, June 19, 2011

Get Url - Protocol/Schema, Domain and (if applicable) Port

From goo.gl/WfuVV and goo.gl/AYp9v


Request.Url.GetLeftPart(UriPartial.Authority)

It will return a string like the following

"http://localhost:51528"

Requesr.Url properties and sample values:

Request.Url
{http://localhost:51528/Account/SendForgotPasswordEmail?email=jon@connor.com}
AbsolutePath: "/Account/SendForgotPasswordEmail"
AbsoluteUri: "http://localhost:51528/Account/SendForgotPasswordEmail?email=jon@connor.com"
Authority: "localhost:51528"
DnsSafeHost: "localhost"
Fragment: ""
Host: "localhost"
HostNameType: Dns
IsAbsoluteUri: true
IsDefaultPort: false
IsFile: false
IsLoopback: true
IsUnc: false
LocalPath: "/Account/SendForgotPasswordEmail"
OriginalString: "http://localhost:51528/Account/SendForgotPasswordEmail?email=jon@connor.com"
PathAndQuery: "/Account/SendForgotPasswordEmail?email=jon@connor.com"
Port: 51528
Query: "?email=jon@connor.com"
Scheme: "http"
Segments: {string[3]}
UserEscaped: false
UserInfo: ""

Friday, June 3, 2011

Javascript Function Objects

Having:

function validateFields() {
// a lot of cool and interesting code goes here.
var a = 1;
var b = 2;
var c = a + b;
}

the following

$('#submit').bind('click', function() {
validateFields();
});

is similar to this:

$('#submit').bind('click', validateFields);

and, to this as well:

$('#submit').bind('click', function() {
var a = 1;
var b = 2;
var c = a + b;
});

So you could say that

function validateFields() {
// a lot of cool and interesting code goes here.
var a = 1;
var b = 2;
var c = a + b;
}

is essentially the same as

var validateFields = function() {
// a lot of cool and interesting code goes here.
var a = 1;
var b = 2;
var c = a + b;
}

i.e. validateFields is not a function/method but an object. Therefore I conclude "Javascript is a different language in disguise."