Request for the permission !

This is an open forum for any mojoPortal topics that don't fall into the other categories.

This thread is closed to new posts. You must sign in to post in the forums.
8/11/2011 5:09:34 AM
Gravatar
Total Posts 92
Нет, я не изменил. До старости глубокой...

Request for the permission !

Dears,

I have mojoportal rev. 2464 (9b143ac6bed7)  default

running on medium trust

I had a workable asp .net upload file, and now i can not use any of them, all the folders have full controll rights on DATA and APP_DATA folders and all under them for both files and folders.

I am using medium trust web.config version

all worked befor.

Just try it by yourself: http://www.aljidara.net/Secure/AlJidaraLogin.aspx?returnurl=%2fAlJidara%2fViewOpportunity.aspx%3fjobID%3d20

Now i am recieving error permission:

ERROR: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

 

here is my code:

 

protected void btnSaveUpload_Click(object sender, EventArgs e)
        {
           
            if (txtUpload.HasFile)
                try
                {
                    long maxAllowed = long.Parse(ConfigHelper.GetStringProperty("ResumeFileMAxSizeInMegaBytes", "0").ToString() );
                    maxAllowed = maxAllowed * 1024 * 1024;
                    //maxAllowed=MB Count * 1024 KB * 1024 Byte

                    string fileName = txtUpload.FileName;
                    if (AllowThisFileType(fileName))
                    {

                        FileInfo mfileinfo = new FileInfo(txtUpload.PostedFile.FileName);
                        if ((mfileinfo.Length < maxAllowed) && (maxAllowed>0))
                        {

                            string SaveFolder = Server.MapPath("\\") + "Data\\Sites\\" + siteSettings.SiteId + "\\userfiles\\cvs\\";

                            if (!Directory.Exists(SaveFolder))
                                Directory.CreateDirectory(SaveFolder);

                            // this is a new projectgalleryImage instance, make sure we don't use the same file name as any other instance
                            string newFileName = fileName;
                            int i = 1;
                            while (File.Exists(SaveFolder + newFileName))
                            {
                                newFileName = i.ToInvariantString() + newFileName;
                                i += 1;
                            }
                            fileName = newFileName;
                            string SaveFile = SaveFolder + fileName;
                            txtUpload.PostedFile.SaveAs(SaveFile);

                            jobUsersCVLink = SiteUtils.GetNavigationSiteRoot() + "//Data/Sites/" + SiteId + "/userfiles/cvs/" + fileName;
                            lblUserUpload.Text = fileName;
                        }
                        else
                        {
                            lblUploadError.Text = Resources.AlJidaraMessagesResources.UploadFileSizeIsNotAllowed;
                        }
                    }
                    else
                    {
                        lblUploadError.Text = Resources.AlJidaraMessagesResources.UploadFileTypeNotAllowed;
                    }
                }
                catch (Exception ex)
                {
                    lblUploadError.Text = "ERROR: " + ex.Message.ToString();
                }
            else
            {
                lblUploadError.Text = Resources.AlJidaraMessagesResources.UploadNotSpecifiedFile;
            }


        }

 

any advice

8/11/2011 5:10:54 AM
Gravatar
Total Posts 92
Нет, я не изменил. До старости глубокой...

Re: Request for the permission !

note:

when i use the internal text editor insert image it work without any problem!

any idea?

8/11/2011 6:42:45 AM
Gravatar
Total Posts 92
Нет, я не изменил. До старости глубокой...

Re: Request for the permission !

Any idea, i am tired runing between server admins, changing code...ets

is that could be because i am using FileInfo?

 

 

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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error:


[No relevant source lines]

Source File: App_Web_rdrle1ug.1.cs    Line: 0

Stack Trace:


[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) +31
   System.Security.CodeAccessPermission.Demand() +46
   System.IO.FileInfo..ctor(String fileName) +131
   AlJidara.Web.UI.Pages.AlJidaraLoginPage.UploadFile(Object src, EventArgs e) +428
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +113
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   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) +10266
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +258
   System.Web.UI.Page.ProcessRequest() +79
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +23
   System.Web.UI.Page.ProcessRequest(HttpContext context) +109
   ASP.secure_aljidaralogin_aspx.ProcessRequest(HttpContext context) in App_Web_rdrle1ug.1.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +478
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +76

8/11/2011 6:47:43 AM
Gravatar
Total Posts 18439

Re: Request for the permission !

Hi Ghalib,

You may think the file system permissions are ok but the error says otherwise, so possibly some file or folder permissions changed.

The fact that the editor upload still works only means the folder where it is uploading is writable but apparently the folder(s) where your custom module is uploading the permissions are not correct, either it can't create the sub folders or it can't put the file there.

If it worked before then it means something changed on the file system permissions in those specific locations.

Hope that helps,

Joe

8/11/2011 6:52:47 AM
Gravatar
Total Posts 18439

Re: Request for the permission !

This kind of code is not as it should be:

 string SaveFolder = Server.MapPath("\\") + "Data\\Sites\\" + siteSettings.SiteId + "\\userfiles\\cvs\\";

Server.MapPath is for converting a web virtual path to a file system path, it should be like this:

string SaveFolder = Server.MapPath("~/Data/Sites/" + siteSettings.SiteId.ToInvariantString() + "/userfiles/cvs/");

for .ToInvariantString() you need

using mojoPortal.Web.Framework;

Hope that helps,

Joe

8/11/2011 7:41:10 AM
Gravatar
Total Posts 92
Нет, я не изменил. До старости глубокой...

Re: Request for the permission !

Thank you Joe,

I just found it... :)

it is sequence logic:

asp Upload upload file to some system temp folder and I request file info while the file there, so the system give that error.

To correct the issue, I have to upload the file to my folder (where i have permissions) and then check for file Info (where FileInfo is a security request and need permissions), and do my jobs with file size check then either delete or accept it.

This must documented somewhere i think.

 

That's all, sequence of jobs :)

8/11/2011 7:46:54 AM
Gravatar
Total Posts 92
Нет, я не изменил. До старости глубокой...

Re: Request for the permission !

Another and more correct and economic way is to use txtUpload.PostedFile.ContentLength instead of FileInfo  if only the size is matter!

You must sign in to post in the forums. This thread is closed to new posts.