Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# read authorization header

HttpContext httpContext = HttpContext.Current;

string authHeader = this.httpContext.Request.Headers["Authorization"];

if (authHeader != null && authHeader.StartsWith("Basic")) {
    string encodedUsernamePassword = authHeader.Substring("Basic ".Length).Trim();
    Encoding encoding = Encoding.GetEncoding("iso-8859-1");
    string usernamePassword = encoding.GetString(Convert.FromBase64String(encodedUsernamePassword));

    int seperatorIndex = usernamePassword.IndexOf(':');

    var username = usernamePassword.Substring(0, seperatorIndex);
    var password = usernamePassword.Substring(seperatorIndex + 1);
} else {
    //Handle what happens if that isn't the case
    throw new Exception("The authorization header is either empty or isn't Basic.");
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: remove index from array c# 
Csharp :: string isnullorempty vs isnullorwhitespace 
Csharp :: c# find largest number in list 
Csharp :: console reset color c# 
Csharp :: get enum name 
Csharp :: c# distinct by property 
Csharp :: how to install jdk on linux manjaro 
Csharp :: Play Sound c# 
Csharp :: c# windows forms print 
Csharp :: unity event 
Csharp :: c# unity 
Csharp :: c# enum to int array 
Csharp :: wpf button 
Csharp :: change dot net core web api routing 
Csharp :: process.start web 
Csharp :: unity new vector3 
Csharp :: swap two numbers c# 
Csharp :: c# if int is in range 
Csharp :: remove all non alphabetic characters from string c# 
Csharp :: unity health bar 
Csharp :: instantiate object in circle 
Csharp :: check if file exist c# 
Csharp :: unity find object by name recursion 
Csharp :: c# insert spaces before capital letters 
Csharp :: how to pass optional guid parameters in c# 
Csharp :: or c# 
Csharp :: c# array.join 
Csharp :: wpf toolbar disable overflow 
Csharp :: asp.net 5 iis HTTP Error 500.19 - Internal Server Error 
Csharp :: c# kill one excel process 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =