title: Text to Speech in ASP.NET - Access is denied... what to do?
body: <p>On my personal website, i would like to make it "pronounce" something</p>
  
  <p>I solved the "concept" problem, as in <a href="https://stackoverflow.com/questions/961546/text-to-speech-in-asp-net">here</a>, and on my desktop it works smoothly when launched from visual web developer. Creates a file, and then an embedded player in the page will play it. Perfect.</p>
  
  <p>So, I uploaded it on the server... I get this error 500:</p>
  
  <blockquote>
    <p>Server Error in '/sapi' Application.
    Access is denied. (Exception from
    HRESULT: 0x80070005 (E_ACCESSDENIED))
    Description: An unhandled exception
    occurred during the execution of the
    current web request. Please review the
    stack trace for more information about
    the error and where it originated in
    the code.</p>
    
    <p>Exception Details:
    System.UnauthorizedAccessException:
    Access is denied. (Exception from
    HRESULT: 0x80070005 (E_ACCESSDENIED))</p>
    
    <p>ASP.NET is not authorized to access
    the requested resource. Consider
    granting access rights to the resource
    to the ASP.NET request identity.
    ASP.NET has a base process identity
    (typically {MACHINE}\ASPNET on IIS 5
    or Network Service on IIS 6) that is
    used if the application is not
    impersonating. If the application is
    impersonating via , the identity
    will be the anonymous user (typically
    IUSR_MACHINENAME) or the authenticated
    request user.</p>
    
    <p>(...)</p>
    
    <p>Source Error:</p>
    
    <p>See it below</p>
    
    <p>Source File:
    c:\mypath\sapi\myfile.aspx.cs
    Line: 21</p>
    
    <p>Stack Trace:</p>
    
    <p>[UnauthorizedAccessException: Access
    is denied. (Exception from HRESULT:
    0x80070005 (E_ACCESSDENIED))]<br>
    SpeechLib.SpVoiceClass.Speak(String
    Text, SpeechVoiceSpeakFlags Flags) +0 
    prova.Button1_Click(Object sender,
    EventArgs e) in
    c:\mypath\sapi\prova.aspx.cs:21
    System.Web.UI.WebControls.Button.OnClick(EventArgs
    e) +111<br>
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String
    eventArgument) +110<br>
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
    eventArgument) +10<br>
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    sourceControl, String eventArgument)
    +13    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection
    postData) +36<br>
    System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean
    includeStagesAfterAsyncPoint) +1565</p>
    
    <p>Version Information: Microsoft .NET
    Framework Version:2.0.50727.3053;
    ASP.NET Version:2.0.50727.3053</p>
  </blockquote>
  
  <p>This is the source</p>
  
  <p>Source Error:</p>
  
  <p>Line 19: <code>myfile.Open(@"C:\mypath\sapi\gen\hi.wav",SpeechStreamFileMode.SSFMCreateForWrite,false);</code>
  <br />
  Line 20: <code>voice.AudioOutputStream = myfile;</code>
  <br />
  <strong>Line 21:</strong> <code>voice.Speak("Hi",SpeechVoiceSpeakFlags.SVSFDefault);</code></p>
  
  <p>I get error on line 21, Voice.speak</p>
  
  <p>That probably means that the aspnet worker user has not some right permission</p>
  
  <p>The generation folder has all the right permissions: an empty file is created.</p>
  
  <p>So, i have to give permission of execute to some system dll?</p>
  
  <p>Do you know which dll? It is <strong>not</strong> <code>bin\Interop.SpeechLib.dll</code>, on this one the aspnet user has full control</p>
  
  <p>Ps: i have full control on the (windows) server (i mean, access by RDC, is not a shared hosting)</p>