0

I have a webAPI that is serving images.

http://{uri}/Data/api/v1/ImageData?objectType=1&dbKey=12

I am trying to consume it in <img> tag dynamically in c# like this:

 var src = string.Format("http://{uri}/Data/api/v1/ImageData?objectType={0}&dbKey={1}", viewType, dbKey);

 html.Append(@"<div class='Image'>");
 html.AppendFormat(@"<span><img src ='{0}'/></span>", src);
 html.Append(@"</div>");

Now, the issue I run into is that I webAPI has a basic authentication that I need to pass a user name and password. How can I do that? unlike this question, I am trying to find better way to pass username and password.

Community
  • 1
  • 1
socialMatrix
  • 1,423
  • 5
  • 20
  • 36
  • Possible duplicate of [How to set the tag with basic authentication](http://stackoverflow.com/questions/3823357/how-to-set-the-img-tag-with-basic-authentication) – Blue Jul 28 '16 at 16:55

1 Answers1

1

If it's your API, then I would consider switching to a token based authentication, which is something that you can pass in a cookie (Or get variable).

It's not currently possible to pass user/password data through an image tag that's agnostic across all browsers.

Blue
  • 22,608
  • 7
  • 62
  • 92