Hai,

In the below code I am deleting a file from client pc

Dim fs
                    fs = Server.CreateObject("Scripting.FileSystemObject")
                    'If fs.FileExists(upfile.PostedFile.FileName) Then
                    fs.DeleteFile(upfile.PostedFile.FileName)
                    'End If

In the Web.config file, I have configured the trust level also. :

<configuration>
 <system.web>
    <identity impersonate='true'/>
  </system.web>

  <location allowOverride="true">
  <system.web>
<trust level="Full" originUrl="" />
</system.web>
</location>
....

BUt while running the application, it is giving the following error. How to change security settings?

Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Exception from HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENIED).

Thanks

Seetha

Dani AI

Generated

: the error is happening because the code is running on the web server, not on the user′s PC. A server-side component (Server.CreateObject / Scripting.FileSystemObject) cannot reach or delete files on a client machine, and COM-based file operations also require full trust and OS-level permissions on the server. pointed to MSDN about trust — useful — but note that many hosts ignore or block changing <trust> in an app web.config; the host or machine.config controls it.

If the real goal is to remove the uploaded file on the server, do not use Scripting.FileSystemObject. Use the .NET I/O APIs and a server path you control. Example (VB.NET):

If FileUpload1.HasFile Then
  Dim fname As String = System.IO.Path.GetFileName(FileUpload1.FileName)
  Dim saved As String = Server.MapPath("~/uploads/" & fname)
  FileUpload1.SaveAs(saved)
  If System.IO.File.Exists(saved) Then System.IO.File.Delete(saved)
End If

Make sure the target folder grants the application pool identity write/modify/delete permissions (IIS APPPOOL\<pool> or NETWORK SERVICE depending on setup). If you truly need COM access, the app must run in Full trust and the COM component must be installed and allowed by the host — often not possible on shared hosting.

If you actually want to delete a file on the client PC, that cannot be done from server-side code without a client-side agent or explicit client action (signed ActiveX, an installed helper, or the user deleting manually). For troubleshooting, check the full stack trace, confirm which path is being passed (client path vs server path), and verify NTFS permissions and the app pool identity.

Hai,

In the below code I am deleting a file from client pc

Dim fs
                    fs = Server.CreateObject("Scripting.FileSystemObject")
                    'If fs.FileExists(upfile.PostedFile.FileName) Then
                    fs.DeleteFile(upfile.PostedFile.FileName)
                    'End If

In the Web.config file, I have configured the trust level also. :

<configuration>
 <system.web>
    <identity impersonate='true'/>
  </system.web>

  <location allowOverride="true">
  <system.web>
<trust level="Full" originUrl="" />
</system.web>
</location>
....

BUt while running the application, it is giving the following error. How to change security settings?

Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Exception from HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENIED).

Thanks

Seetha

http://msdn.microsoft.com/en-us/library/tkscy493.aspx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.