System.Security.SecurityException:在日历上

时间:2011-01-30 22:30:19

标签: asp.net vb.net

您好我在远程计算机(互联网)上查看我的应用程序时收到此错误消息

安全异常说明:应用程序尝试执行安全策略不允许的操作。要授予此应用程序所需的权限,请与您的系统管理员联系或在配置文件中更改应用程序的信任级别。

例外详细信息: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 

Line 7:      Dim oBF As New BinaryFormatter()
Line 8:      Dim oFS As FileStream
Line 9:      Dim strPath As String = Path.GetTempPath & "schedule.Bin"
Line 10: 
Line 11:     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


Source File: D:\Hosting\4423045\html\please-god\appointmentscheduler.aspx.vb    Line: 9 

堆栈追踪:

以下是该应用程序的完整代码:

    Imports System.IO
    Imports System.Runtime.Serialization.Formatters.Binary

    Partial Class appointmentscheduler
        Inherits System.Web.UI.Page
        Dim arrCalendar(12, 31) As String
        Dim oBF As New BinaryFormatter()
        Dim oFS As FileStream
        Dim strPath As String = Path.GetTempPath & "schedule.Bin"

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If (Cache("arrCalendar") Is Nothing) Then
                If (File.Exists(strPath)) Then
                    oFS = New FileStream(strPath, FileMode.Open)
                    arrCalendar = DirectCast(oBF.Deserialize(oFS), Array)
                    oFS.Close()
                    Cache("arrCalendar") = arrCalendar
                End If
            Else
                arrCalendar = Cache("arrCalendar")
            End If
        End Sub

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        arrCalendar(Me.myCalendar.SelectedDate.Month, Me.myCalendar.SelectedDate.Day) = Me.myNotes.Text
        oFS = New FileStream(strPath, FileMode.Create)
        oBF.Serialize(oFS, arrCalendar)
        oFS.Close()
        Cache("arrCalendar") = arrCalendar
    End Sub

    Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        arrCalendar(Me.myCalendar.SelectedDate.Month, Me.myCalendar.SelectedDate.Day) = ""
        oFS = New FileStream(strPath, FileMode.Create)
        oBF.Serialize(oFS, arrCalendar)
        oFS.Close()
        Cache("arrCalendar") = arrCalendar
        Me.myNotes.Text = ""
    End Sub

    Protected Sub myCalendar_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles myCalendar.DayRender
        If arrCalendar(e.Day.Date.Month, e.Day.Date.Day) <> "" Then
            e.Cell.BackColor = Drawing.Color.Red
        End If
    End Sub

    Protected Sub myCalendar_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles myCalendar.SelectionChanged
        Me.myNotes.Text = ""
        If arrCalendar(Me.myCalendar.SelectedDate.Month, Me.myCalendar.SelectedDate.Day) <> "" Then
            Me.myNotes.Text = arrCalendar(Me.myCalendar.SelectedDate.Month, Me.myCalendar.SelectedDate.Day)
        End If
    End Sub
End Class

有人可以帮我解决或告诉我该怎么做。

1 个答案:

答案 0 :(得分:0)

运行该应用程序的用户无权访问临时文件夹或特定文件(schedule.Bin)。

这可能有所帮助:

How Do I Determine the Security Account that IIS Uses to Run My Web Site?