2009-11-10 280 views
0

我上傳的視頻和images.In本地服務器的Web應用程序,工作perfectly.But當我上傳了該web服務器有一個錯誤,我不能上傳files.The誤差安全異常

Security Exception 
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: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. 

Source Error: 

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL: 

1. Add a "Debug=true" directive at the top of the file that generated the error. Example: 

    <%@ Page Language="C#" Debug="true" %> 

or: 

2) Add the following section to the configuration file of your application: 

<configuration> 
    <system.web> 
     <compilation debug="true"/> 
    </system.web> 
</configuration> 

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode. 

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario. 

我使用的代碼上傳是..

Dim connectionstring As String = ConfigurationManager.ConnectionStrings("UploadConnectionString").ConnectionString 
        connection = New SqlConnection(connectionstring) 
        Dim cmd As New SqlCommand("insert into FileM (FileName,[File],FilePath,FileSize)" + "values(@FileName,@File,@FilePath,@FileSize)", connection) 
        cmd.Parameters.Add("@FileName", SqlDbType.NVarChar, buffer.Length).Value = FileUpload1.FileName 
        cmd.Parameters.Add("@File", SqlDbType.VarBinary).Value = buffer 
        cmd.Parameters.Add("@FileSize", SqlDbType.BigInt).Value = file.ContentLength 
        cmd.Parameters.Add("@FilePath", SqlDbType.VarChar).Value = path 
        Using connection 
         connection.Open() 
         Dim i As Integer = cmd.ExecuteNonQuery 

        End Using 

已經有這種類型的上傳或任何問題,希望通過經營業務邏輯層插入到表?

回答

1

此錯誤可能是由於您的應用程序運行的帳戶沒有權限寫入您嘗試存儲文件的目錄。

+0

我該如何解決這個問題? – user85511 2009-11-10 10:37:58

+0

授予您的應用程序在您正在存儲文件的目錄的讀/寫權限下運行的帳戶。 – 2009-11-10 10:43:43

+0

從你上傳的代碼片段看來,你將文件存儲到數據庫中應該沒問題。唯一不清楚的是你正在使用的'path'變量。這個變量是如何初始化的? – 2009-11-10 10:50:45