开发者

ASP.NET (MVC) Get username from URL http://username@myapplication.com

开发者 https://www.devze.com 2023-01-23 00:58 出处:网络
Is ther开发者_运维技巧e any way to retrieve username from this 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://","");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消