AjaxFileUpload don't flush %windir%\temp\ - asp.net

I have a considerable issue, found by hosting several ASP.NET websites (7 ~ 15) with the AjaxFileUpload server control of the AjaxControlToolkit library (the latest version):
while the control is processing file, temporary files are saved in the system temporary folder (%windir%\temp), but it won't flush that after the request is complete.
I don't know if this is a folder permission problem, or an AjaxFileUpload bug.
This is the result after 2 years of hosting, a huge stack of temporary folders:
Top
Bottom
There is any way to override that behavior, or i must manually flush that folder every 1-2 months ?
Thanks in advance

If you don't use SaveAS() method, you must deleted yourself.
example:
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) {
// Save uploaded file to a database table
e.DeleteTemporaryData();
}
more info here: http://stephenwalther.com/archive/2013/04/30/april-2013-release-of-the-ajax-control-toolkit

Related

Can't see an added class

I created an ASP.Net project in .Net 2.0 and uploaded all files to the server (dlls and cs files) to the server. It is a very basic HTML page with a button on it.
When I loaded it on the server, it was okay.
I added a static class to my project and used it when the button was clicked:
protected void btnUse_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtData.Text))
Utils.SaveData(txtData.Text);
}
When I uploaded it, I get the following error:
Server Error in '/' Application. Compilation Error Description: An
error occurred during the compilation of a resource required to
service this request. Please review the following specific error
details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'Utils' does not exist in the
current context
What else should I upload?
The code change can't take effect until the code is compiled, and the result is the .dll file(s). So two things to take care of here:
In order to add the class, you need to add it to the source code (which you've done), re-compile into the .dlls, and upload the new .dlls to the server.
You don't need (and shouldn't have) the .cs files on the server. That's the source code, not the compiled result. The compiled result is the .dlls. The server needs those, the markup pages (.aspx, .ascx, etc.), and any other resources (images, JavaScript files, .css files, etc.), but not the C# source code.

Download Excel file into Unprotected View

I am running a website written in ASP.net and any Excel file you download gets downloaded in Protected View. This causes an extra few clicks for the user to be able to edit it.
How can I alter this so the files always are downloaded in Unprotected View?
It is possible IF you have control over the computers who can download from your website. Than you can add your website to the trusted websites and everything will work fine.
How to do it, you have to google - our Admins had to google a lot to find it out, and I do not know the details :/
Check out the following links:
Disable Protected View in Office 2010,
https://amsterdam.jira.com/wiki/display/MAN/How+to+disable+protected+view+in+Excel+2010
Disable Protected View in Office 2007 and 2010 by using Trust
Settings,
http://helpmerick.com/solution-to-microsoft-outlook-2007-or-2010-not-opening-word-or-excel-attachments.htm
How to edit your Excel settings.
http://office.microsoft.com/en-us/excel-help/what-is-protected-view-HA010355931.aspx
What is Protected View?
"Files from the Internet and from other potentially unsafe locations can contain viruses, worms, or other kinds of malware, which can harm your computer. To help protect your computer, files from these potentially unsafe locations are opened in Protected View. By using Protected View, you can read a file and inspect its contents while reducing the risks that can occur."
Why is my file opening in Protected View?
Protected View is a read-only mode in which most editing functions have been disabled. There are several reasons why a file opens in Protected View:
The file was opened from an Internet location - When you see the message in Protected View that states This file originated from an Internet location and might be unsafe. Click for more details., this is because the file is being opened from the Internet. Files from the Internet can have viruses and other harmful content embedded in them. We recommend that you edit only the document, if you trust its contents.
The file was received as an Outlook 2010 attachment and your computer policy has defined the sender as unsafe - When you encounter the message in Protected View that states This file originated as an e-mail attachment and might be unsafe. Click for more details., this is because the file was received from a potentially unsafe sender.
The file was opened from an unsafe location - When you encounter the message in Protected View that states This file was opened from a potentially unsafe location. Click for more details. the file was opened from a folder that is unsafe. An example of an unsafe location is your Temporary Internet Files folder.
The file is blocked by File Block
File validation failure - When you encounter a message in Protected View that states Office has detected a problem with this file. Editing it may harm your computer. Click for more details. It has occurred because the file did not pass file validation.
NOTE - You can learn more about file validation failures in Problem detected with a file.
The file was opened in Protected View by using the Open in Protected View option. When you encounter the message in Protected View that states This file was opened in Protected View. Click for more details., this is because you chose to open the file in Protected View. This can be done by using the Open in Protected View option: Click the File tab. In the Microsoft Office Backstage view, click Open. On the Open dialog box, click the arrow on the Open button. From the list, select Open in Protected View. The following image is an example of Protected View appearing when Open in Protected View is selected.
IMPORTANT System administrators can extend the list of potentially unsafe locations to include additional folders also considered unsafe."

Adding Cache headers via a Web.config for specific locations only

We have an application that has been developed by the third party, and I don't want to go back to them to get them to add in cache control for specific pages.
All the pages that need caching disabled are in a single directory.
The issue is that IE seems to not follow Cache-control:nocache properly, so we need to add in Pragma:nocache and cache age as well.
Is there a way to do this using configs in the directory? will it cascade through all child directories? Can it be done via the main web.config?
To be clear, I'm not looking for a way to do this via code, it needs to be via configuration of either IIS or the web.config files.
We're using ASP.NET 2.0 and 4.0, on IIS 6.0.
This can be done in IIS using the UI, it's actually quite easy, or atleast it was in my use case.
All you do is simply open up IIS manager, navigate to the site and then the directory you want to add the headers to Right Click -> properties.
Click the "Headers" tab, and add in the headers you require.
This goes recursively down the child directories, and adds the headers before any added by the code.
In IIS 7.0/7.5, you can use the StaticContent section of a web.config in each of the directories.
You can do that on global.asax
protected void Application_BeginRequest(Object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
string cTheFile = HttpContext.Current.Request.Path;
if (cTheFile.Contains("/ExtraDir/"))
{
// add your header here
app.Response.AppendHeader("Pragma", "no-cache");
}
//... rest code of...
}

How to open folder from web page

I want to open folder from web page on clicking on a button.
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("file://C://inetpub//wwwroot//myproject");
}
Please suggest me proper code in C# for open myproject folder.
This can be ONLY done in IE, no other browser has access to file system. You can assign the path to href of an anchor tag, and it should work.
Open
If you're looking at adding functionality to your website so that a user can upload files to it then look at this project on MSDN. It'll show you how to do this with an example ASP.NET project.
Maybe this statement can help you:
System.Diagnostics.Process.Start(#"C:\");

Custom Errors for "App" folders? (ASP.NET)

Where can I setup custom errors for directories in my application such as App_Code, App_Browsers, etc.? I already have customErrors configured in the web.config and that works as expected. For example,
http://www.mysite.com/bla.aspx > redirects to 404 page
but
http://www.mysite.com/App_Code/ > displays "The system cannot find the file specified."
There's no physical App_Code directory for my site. Is this something that I can change in IIS?
You are trying to server content from an Protected Folder... ??
I think you might need to allow access to these folders to get the nice errors you are looking for...
http://www.webdavsystem.com/server/documentation/hosting_iis_asp_net/protected_folders
That being said... there is a reason these folders are protected.
I would never put anything i needed IIS to serve in protected folders.
But there are always reasons to do do something? i have broke a few rules in my short lifespan :)
UPDATE:
Found this when i tried this locally: http://support.microsoft.com/kb/942047/
Looks like those reserved directories throw special 404's you might be able to get IIS to Target the 404.8 type... with out opening up serving to those directories
I believe you will need to set the error pages in IIS itself, as the requests you talk about never reach the ASP.NET application. The reason your first example works is because IIS recognises the .ASPX extension and forwards it to ASP.NET.
One way is to provide a redirect in the global.asax file:
void Application_Error(object sender, EventArgs e)
{
//uncomment this to narrow down 'helpful' microsoft messages
//HttpRequest request = ((HttpApplication)sender).Context.Request;
Exception ex = Server.GetLastError();
//ErrorManager is a custom error handling module
ErrorManager.ProcessError(ex);
Response.Redirect("~/error.aspx?error=" + HttpUtility.UrlEncode(ex.Message), true);
}
{ On a side note, I was getting an exception that I just couldn't track down - it just said 'file not found' but didn't say which file was missing. It turned out to be a broken image reference in a css file - breaking on line two of the code above helped identify the missing file }
Add a Wildcard Mapping to IIS to run ALL Requests through ASP.net, then you can use Global.asax to handle the error.
Taken from here:
Follow these steps to create a wildcard script map with IIS 6.0:
Right-click a website and select Properties
Select the Home Directory tab
Click the Configuration button
Select the Mappings tab
Click the Insert button (see Figure 4)
Paste the path to the aspnet_isapi.dll into the Executable field (you can copy this path from the script map for .aspx files)
Uncheck the checkbox labeled Verify that file exists
Click the OK button

Resources