ASP.NET (MVC) Get username from URL http://username@myapplication.com
Is ther开发者_运维技巧e 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?
You're looking for the Uri
class:
var uri = new Uri(someString, UriKind.Absolute);
var user = uri.UserInfo;
If that's the guaranteed string you might try something like:
string myString = "http://username@myapplication.com";
if(myString.Contains("@"))
{
return myString.Split('@')[0].Replace("http://","");
}
精彩评论