Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

Security exception with GetCreationtime()

$
0
0

I have got two applications each with GetCreationTime() seemingly in very similar contexts. One throws an error and the other one doesn't. I cannot find why the bad one is bad.

I have pasted (what I hope are) the relevant bits below. Can anyone give me a clue, please ?

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.



[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.File.GetCreationTimeUtc(String path) +114
   System.IO.File.GetCreationTime(String path) +24
   _Default.Files_clear() in d:\websites\3bbb3.co.uk\wwwroot\Default.aspx.vb:94
   _Default.Button1_Click(Object sender, EventArgs e) in d:\websites\3bbb3.co.uk\wwwroot\Default.aspx.vb:19
   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.default_aspx.ProcessRequest(HttpContext context) +37
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75


FROM APPLICATION Add_All


    Protected Sub Files_clear()
        '
        ' Looks through all the files in \Dox and deletes all those
        ' older than eight days
        '
        Dim root1 As String
        root1 = HttpContext.Current.Server.MapPath("Dox")
        '
        Dim ak As DateTime, ay As DateTime, a_now As DateTime
        Dim myDirInfo As New DirectoryInfo(root1)
        Dim ArrayFileInfo As Array
        Dim myFileInfo As FileInfo
        Dim file_name As String
        '
        a_now = DateTime.Now
        '
        ArrayFileInfo = myDirInfo.GetFiles()
        '
        For Each myFileInfo In ArrayFileInfo
            file_name = myFileInfo.Name
            ak = File.GetCreationTime(file_name)  '**** THIS GIVES AN ERROR
            ay = ak.AddDays(8)
            If a_now > ak Then
                File.Delete(file_name)
            End If
        Next
        '
    End Sub
 
FROM APPLICATION Files_shift

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        '
        ' This gets the creation time of a named file
        '
        Dim ak As DateTime, ay As DateTime, a_now As DateTime
        '
        Dim root1 As String, filenameS As String
        '
        root1 = HttpContext.Current.Server.MapPath("Dox")
        '
        filenameS = root1 & "\" & "bach.txt"

        ak = File.GetCreationTime(filenameS)   '**** THIS ONE IS OK
        Label2.Text = ak
        '
        ay = ak.AddDays(3)
        Label3.Text = ay
        '
        a_now = DateTime.Now
        '
        ' This is just to check syntax
        '
        If a_now > ak Then
            label4.text = "Files created earlier"
        End If
        '
    End Sub


Viewing all articles
Browse latest Browse all 4737

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>