Jakub Chodounsky
Jakub Chodounsky

Reputation: 625

ASP.NET (MVC) Get username from URL http://[email protected]

Is there any way to retrieve username from this

http://username@myapplication.com

type of address in ASP.NET MVC (optionally in ASP.NET) from current request?

Upvotes: 0

Views: 373

Answers (2)

SLaks
SLaks

Reputation: 887777

You're looking for the Uri class:

var uri = new Uri(someString, UriKind.Absolute);
var user = uri.UserInfo;

Upvotes: 3

Joel Etherton
Joel Etherton

Reputation: 37543

If that's the guaranteed string you might try something like:

string myString = "http://[email protected]";

if(myString.Contains("@"))
{
    return myString.Split('@')[0].Replace("http://","");
}

Upvotes: 0

Related Questions