DotNetZip FileIOPermission - can't add files to zip, though I have rights - asp.net

I completely fail to get dotnetzip to add files to a .zip file
i can:
using (ZipFile zip = new ZipFile())
{
zip.AddEntry("test.txt", DateTime.Now.ToString());
zip.Save(Response.OutputStream);
}
This is completed correctly and produces a zip file for download that can be opned with the text file inside
Problem: Trying to add files like this:
zip.AddFile(Server.MapPath("/Files/test.txt"), "Files");
Always result in something like this:
[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() +61
System.IO.File.GetLastWriteTimeUtc(String path) +114
System.IO.File.GetLastWriteTime(String path) +24
Ionic.Zip.ZipEntry.Create(String nameInArchive, ZipEntrySource source, Object arg1, Object arg2) in c:\DotNetZip\Zip\ZipEntry.cs:2405
Ionic.Zip.ZipEntry.CreateFromFile(String filename, String nameInArchive) in c:\DotNetZip\Zip\ZipEntry.cs:2313
Ionic.Zip.ZipFile.AddFile(String fileName, String directoryPathInArchive) in c:\DotNetZip\Zip\ZipFile.AddUpdate.cs:406
Ionic.Zip.ZipFile.AddFile(String fileName) in c:\DotNetZip\Zip\ZipFile.AddUpdate.cs:296
MultiFileDownloader.WebForm1.Button1_Click(Object sender, EventArgs e) in D:\WORK\dynamicweb\StandardModules\MultiFileDownloader\Source\MultiFileDownloader\WebForm1.aspx.cs:54
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.webform1_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\ade7bc1a\c2b11481\App_Web_txhzteca.0.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Note: My code can read/create the files with no problem. IIS user (and everyone infact) have total permissions to the files in question. IIS 7.5, win2008r2
How can I grant the DotNetZip assembly the same rights?

Figured it out my self:
On application pool I set the Load User profile to true....problem solved. Guess the assembly was running without any user at all (not everyone, not anomnynous, not no one)

Related

ASP Oracle Connection Error

I've wrote some connection code in asp for oracle. Its working fine from server A.
When I tried same code from server B it give me error.
Here is the stack trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Oracle.DataAccess.Client.OracleConnection.Open() +9007
WebApplication4.Login.submit_Click(Object sender, EventArgs e) +238
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9633194
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
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) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
I'm using oracle data access dll. Its version is v2.0.50727.
I downloaded it from nuget.
Run your code using:
Debug mode
Check connection string if empty
Access your database manually to simulate the error

Email Security Exception in ASP.NET

Security ExceptionDescription: The application attempted to perforanoperation 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.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source Error:
Line 45: {
Line 46: smtp.Host = "smtp.gmail.com";
Line 47: smtp.Port = 587;
Line 48: smtp.EnableSsl = true;
Line 49: smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
Source File: d:\inetpub\vhosts\softsoftware.in\designscentre\asktheexpert.aspx.cs Line: 47
Stack Trace:
[SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, 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() +61
System.Net.Mail.SmtpClient.set_Port(Int32 value) +106
asktheexpert.sendbtn_Click(Object sender, EventArgs e) in d:\inetpub\vhosts\softsoftware.in\designscentre\asktheexpert.aspx.cs:47
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.asktheexpert_aspx.ProcessRequest(HttpContext context) in App_Web_vkk6wpqv.2.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Version Information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5483
Security ExceptionDescription: The application attempted to perforanoperation 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.
website work in Localhost correctly.
but Error on server .
Please Help me how to solve this error.

An item with the same key has already been added. (Ajaxcontroltoolkit)

Can anyone help with this issue? I recieve this error in our logs every so often but the users say they didnt experience any issues.
Thanks
Error Description
Exception of type 'System.Web.HttpUnhandledException' was thrown.Inner
Exception-->An item with the same key has already been added. -
System.ArgumentException: An item with the same key has already been
added. at System.Collections.Generic.Dictionary`2.Insert(TKey key,
TValue value, Boolean add) at
AjaxControlToolkit.ToolkitScriptManagerHelper.GetAssembly(String name)
at
AjaxControlToolkit.ToolkitScriptManagerCombiner.IsScriptCombinable(ScriptEntry
scriptEntry, Boolean enableCdn) at
AjaxControlToolkit.ToolkitScriptManagerCombiner.WriteScripts(List`1
scriptEntries, TextWriter outputWriter, Boolean enableCdn) at
AjaxControlToolkit.ToolkitScriptManagerCombiner.GetCombinedRegisteredScriptContent(Boolean
enableCdn) at
AjaxControlToolkit.ToolkitScriptManager.LoadScriptReferences(HttpContextBase
context, String[] bundles, Boolean forCombineAndMinify) at
AjaxControlToolkit.ToolkitScriptManager.OnLoad(EventArgs e) at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Stack Trace:
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)Occured onSystem.Web - Boolean
HandleError(System.Exception) Inner Exception-->
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at AjaxControlToolkit.ToolkitScriptManagerHelper.GetAssembly(String name)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.IsScriptCombinable(ScriptEntry
scriptEntry, Boolean enableCdn)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.WriteScripts(List`1
scriptEntries, TextWriter outputWriter, Boolean enableCdn)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetCombinedRegisteredScriptContent(Boolean
enableCdn)
at AjaxControlToolkit.ToolkitScriptManager.LoadScriptReferences(HttpContextBase
context, String[] bundles, Boolean forCombineAndMinify)
at AjaxControlToolkit.ToolkitScriptManager.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
You are registering scripts with the same key (name). Check ScriptManager <Scripts> section, and all RegisterClientScriptBlock and RegisterStartupScript calls for duplicates.
Also use IsClientScriptBlockRegistered and IsStartupScriptRegistered before registering any scripts to avoid that in the future.

At the time upload files from my website I'm getting this error

I am developing website in ASP.NET Framework in which there is one page where user needs to upload file for registration purpose it should be in pdf format but when i click on submit button i m getting error page.
Below is stack trace
Could not find a part of the path 'E:\ASPapps\youth\Resumes\innovation\About Stacks.pdf'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'E:\ASPapps\youth\Resumes\innovation\About Stacks.pdf'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[DirectoryNotFoundException: Could not find a part of the path 'E:\ASPapps\youth\Resumes\innovation\About Stacks.pdf'.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +224
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, Boolean useLongPath) +1142
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +83
System.Net.Mail.AttachmentBase.SetContentFromFile(String fileName, String mediaType) +76
System.Net.Mail.Attachment..ctor(String fileName, String mediaType) +38
InventeamHP.innovation_Register.SendMail(String emailid, String bccemailid, String body) +715
InventeamHP.innovation_Register.lbtnESubmit_Click(Object sender, EventArgs e) +8078
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +118
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +113
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +9
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +176
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
Try using code like this (I don't know your code):
ASPX:
<input id="up" runat="server" type="file" />
Code behind:
up.PostedFile.SaveAs(HttpContext.Current.Server.MapPath("/")+"yourFolder\\"+up.PostedFile.FileName);
and also as Darin Dimitrov said, make sure that your folder exists.

Access is denied when trying to open an exe application from a website

In my website, I tried to open a windows application (.exe) upon a button click. But it showing "Access is denied".
Stack trace:
[Win32Exception (0x80004005): Access is denied]
System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) +614
System.Diagnostics.Process.Start() +56
ghs.btnTry_Click(Object sender, EventArgs e) in c:\inetpub\vhosts\ddrivestudio.com\httpdocs\tanishq\ghs.aspx.cs: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) +1565
Button click event:
Process p = new Process();
p.StartInfo.FileName = Request.MapPath("~/App/App1.exe");
p.Start();
Hope the following links already have an answer.
Reference:
1.Which permissions are required to enable process.start via asp.net application?
2. Access is denied at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)

Resources