2009-11-10 136 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