2009-11-11 83 views
0

我有一個用於上傳視頻和圖像的web應用程序。在本地服務器上工作完美。但是當我上傳到web服務器時出現錯誤,我無法上傳文件。錯誤是安全異常錯誤

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. 

[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.] 
    System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0 
    System.Security.CodeAccessPermission.Demand() +58 
    System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +644 
    System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +61 
    System.IO.FileStream..ctor(String path, FileMode mode) +55 
    System.Web.HttpPostedFile.SaveAs(String filename) +99 
    System.Web.UI.WebControls.FileUpload.SaveAs(String filename) +23 
    Uploader.VideoUpload.ButtonUpload_Click(Object sender, EventArgs e) +195 
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111 
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110 
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785 
    System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242 
    System.Web.UI.Page.ProcessRequest() +80 
    System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21 
    System.Web.UI.Page.ProcessRequest(HttpContext context) +49 
    ASP.forms_videoshow_aspx.ProcessRequest(HttpContext context) +37 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75 

我使用的代碼上傳是..

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 

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

+0

您是否嘗試過設置debug =「true」以查看異常詳細信息?如果是這樣,你可以在這裏發佈細節嗎? – 2009-11-11 05:34:40

回答

1

您需要將寫入權限授予服務器上的文件夾。如果它是Windows Server,則將權限授予「網絡服務」。

+0

+1以上答案正確。更具體地說,如果這是一臺Windows服務器,請確保您向網絡服務添加了「寫入」權限。 – 2009-11-11 07:07:03

+0

它是一個網絡服務器。 – user85511 2009-11-11 07:15:46

+0

還應該應用 - 嘗試授予「網絡服務」的寫入訪問權限:-) – IrishChieftain 2009-11-11 07:44:56