I’m using an ASP.MVC .net web app.
This project will display another url inside/embeded the view (.cshtml). But when we display that other web inside our project, the second server embeded displays a prompt asking for the credentials.
We want to avoid that since the user has already login in our web. So, in order to prevent the user to write his credentials twice, we want to send the credentials via embeded url.
.cshtml view:
@{
string cadena = "https://UserName:UserPassword@URL?rs:embed=true";
}
<div class="container">
<object class="responsive-iframe" data=@cadena></object>
</div>
The problem is that this solution only works on Firefox because Edge/Chrome blocks embeded urls. So the only solution we find is to send the credentials to the server via cookies. But I don’t know how to do it.
This is the controller but it keeps displaying the prompt asking for the credentials:
public ActionResult InformePagares()
{
//I found this on internet, but it looks incomplete. I don't know how to do it
HttpClient httpClient = new HttpClient { BaseAddress = new Uri(URL) }; //This url is the same on the view (without "UserName:UserPassword" and without "?rs:embed=true")
string encoded = System.Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes($"{Username}:{Password}"));
httpClient.DefaultRequestHeaders.Add("Authorization", $"Basic {encoded}");
return View();
}
How can I send cookies credentials from a .net web app (MVC) to another web server from controller (#C) or from the view using HTML, javascript, jquery…?