title: C# Building images dynamically and returning to view
body: <p>I have a requirement where I need to generate a custom image (or several images) when a user hits our page. The user is emailed a special link, that link has the users encrypted id as one of the parameters so we can distinguish who is accessing our site. </p>
  
  <p>We must build an image that is unique to that user (their name, specific icons, etc). </p>
  
  <p>I am currently accomplishing this by using string interpolation. I have an SVG template with values such as @UserName, @Icon1, etc. I then pass that raw SVG data to my View and wrap it around @Html.Raw() to render the custom image. </p>
  
  <p>I am interested if there is a more efficient way of doing this, CPU and memory usage seem fine in my testing but I am concerned when this scales we will see a bottle neck or other issues that weren't discovered in development. The SVG is fairly large about 9500 characters, and there are cases where we are sending up to 10 different images on one single request. </p>
  
  <p>Controller: </p>
  
  <pre><code>public ActionResult Index(string id)
  {
      string svgTemplate = GetTemplateFromDb(id);
      svgTemplate = svgTemplate.Replace("@Name", "SomeName").Replace("@Address", "SomeAddress");
  
      BuiltItem images = Build(svgTemplate);
  
      return View(images);
  
  }
  </code></pre>
  
  <p>View: </p>
  
  <pre><code>&lt;div&gt;
      @Html.Raw(Model.data)
  &lt;/div&gt;
  </code></pre>