I have currently moved my asp.net 4.0 web application onto IIS7 (windows 2008 server). I used a test folder to hold files from a directory on the localhost machine, however; when I moved the aspx file over and changed the code(on the server), the application keeps throwing this error
Could not find a part of the path 'C:\Users\***\Desktop\TestFolder\'.
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 'C:\Users\****\Desktop\TestFolder\'.
I only have two functions that deal with directories and neither function points to that test directory anymore.
private int checkForFileNumbers()
{
string url = "c:/***/realfolder";
DirectoryInfo directory = new DirectoryInfo(url);
return directory.GetFiles().Length;
}
private void checkForFiles()
{
string url = "c:/***/realfolder";
DirectoryInfo dir = new DirectoryInfo(url);
foreach (FileInfo files in dir.GetFiles())
{
FileDropDownList.Items.Add(files.Name);
}
}
I have tried commenting everything in this aspx file out, only to find that this problem still occurs. I performed the issrestart from the cmd line and nothing changed. Any help would be appreciated.
This is a deployment problem. Your error message is clearly out of sync with your current code. The actual code that is being run from IIS must be coming from an out-of-date binary. As a starting point, I would delete all DLLs in your bin directory on the server and redeploy fresh DLLs. The may also require you to refresh your aspx files depending on what kind of project type you're using.
Once you get this sorted out, I would take another look at how you are deploying updates to your site. Visual Studio and IIS 7 offer some neat deployment options if you want to go that way. Also, you could deploy via Git or SVN. But deployment by manual replacing single files is going to lead you to the type of trouble you are currently experiencing.
If realFolder directory exists under root of your web-app or itself is root then use Server.MapPath method to get real path of virtual folder.
For instance,
String rootPath=Server.MapPath("~"); // It will return real path of current web-app's root.
//OR - In case if want use Server property from separate code file.
String rootPath=HttpContext.Current.Server.MapPath("~/testFolder");
Since you're not referencing the path in your code, it's probably either in one of your config files, HttpModules, Global.asax, or perhaps a DLL.
What other components are you using?
Before moving it to a server, have you tried running the site under IIS on your local machine? Maybe attach a debugger and see where the error is thrown?
Oh, FWIW, the IIS AppPool identity will need to have read permission for your C:/***/whatever folder.
Related
I recently bought a new computer. I moved the drives from my old computer to the new one, installed everything I needed to and opened my project. Now I'm trying to run my project in IIS express but it displaying an error specifying an html output as log file.
When I look at the html problem, it's a 500 error message generated by what looks likes an IIS page. It's saying that the config file cannot be found:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid
Config File
\\?\F:\Development\MyProject\API\web.config
When I switched to the new machine drive letters were changed, so the code I'm running is no longet on drive F like in the message above - it's now on a different drive. I've looked in my code - I have no reference anywhere to a specific path.
I've tried to do clean and rebuild but it doesn't work.
If I look inside files for the path I see that the DLLs are compiled with PDB file path inside them. Why is that? And what happens later on on production?
Also, how do I fix this problem? why does it keeps looking for old location?
I'm fairly sure the IIS Express metabase still has the old path configured for this site. Please see the following answer for how to locate the metabase file (it's usually here: \Documents\IISExpress\config\applicationhost.config):
Where is the IIS Express configuration / metabase file found?
I'm not sure what the most correct way is to correct the problem, but you should be able to manually edit this file and update the "physicalPath" attribute for your site to the correct path to resolve this problem.
I don't know the exact cause of my problem, but the solution was to delete all bin directories from all project folders and re-compile.
To delete the bin directory from all my project I wrote the following PowerShell script:
Get-ChildItem -Path . -Filter *bin* –Recurse | Remove-Item -Recurse -Confirm
Am developing asp .Net web application.
In one of my aspx file am using file to download using generic handler. Everything works great. But when am testing i felt a strange problem. That, if am uploading a image or document with file name containing aspx character for Eg; aspxphoto as file name.
Uploading doesnt have any any problem but when i try to download it is throwing error in Generic handler file as
Object reference not set to an instance of an object.
Can anyone help me why this problem happends and how can i fix it?
You will not be able to do this. The IIS handler wants to "handle" the ASPX. You should simply not allow it, or if you have to, rename it to .aspx.uploaded or something. If you allowed, it you could open yourself to hacking.
As another option, you may be able to create a virtual that implements ("no processing") - possibly using the HTTP Handler under the virtual and just disabling script / execute permissions (under handler >> Edit Feature Permission >> Script OR under Virtual >> Edit permissions >> Special >> Turn Execute off.
I would not recommend the last, since it will add complexity when migrating between test and live AND for recovery (DR).
In a common ASP.NET Web Forms page, I specify the location of a backup file as follows:
string backupFilePath = "../data/backups";
ICronjobTask[] tasks = new ICronjobTask[]
{
new FileBackupCronjobTask(backupFilePath)
};
The ICronjobTask is executed later on. When calling the published page on my web server, an error message tells me that parts of the path "C:\Windows\SysWOW64\inetsrv\data\backups\file.txt could not be found.
Why does ASP.NET publish my local directory structure? How do I turn this off?
You're displaying the raw exception error message, is my guess. Whenever you do that, you risk giving away information that you don't want to be made public. Instead of doing that, you should interpret the exception and give general information to the user.
The solution was to use the Server.MapPath(string path) method that returns the physical path corresponding to the specified logical one.
I've got a C# 3.5 web service that works fine when its accessed at http://domain/foo/bar/WS.asmx
The /foo/bar part could change in the future so I want to give people a more stable URL that I could update without requiring any changes from them. I created a site in IIS and set it's Home Directory to where WS.asmx is. Now when I try to access it from http://domain2/WS.asmx, I get:
Description: An error occurred during
the parsing of a resource required to
service this request. Please review
the following specific parse error
details and modify your source file
appropriately.
Parser Error Message: Could not create
type 'Namespace.WS'.
Source Error: Line 1: <%# WebService
Language="C#" CodeBehind="WS.asmx.cs"
Class="Namespace.WS" %>
The assemblies in both cases are at http://domain/bin but when I come from domain2 it doesn't seem to know where to find the \bin that is 3 folders up in the file system.
The namespace/classes are more descriptive than that, I just made them basic for the purposes of this question.
Sorry, AFAIK you can't pull DLLs from explicit file paths outside the root of your website. You generally have two choices:
1) use the /bin directory of the current app (make a copy of the other app's /bin)
2) put the DLL into the Global Assembly Cache (GAC)
BTW, this has been asked in a few other spots on SO, like here.
One thing you could do, if your /bin DLLs are only used inside /foo/bar/, is to convert into an IIS application, and then move the DLLs into a new /foo/bar/bin directory. Then you'd only have one copy of the DLL's to manage.
I have written some code that uses an Access DB, on my localhost the following - Select, Insert, and Delete queries work just fine and do what I programmed them to do. When I move the application to the staging server, the application throws errors when Inserting and deleting, however the select statements work just fine. I have made sure all permissions are read/write as far as I can tell, does anyone know what I am missing. See the error below.
~~~~~
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.Data.OleDb.OleDbException: Could not delete from
specified tables.
Source Error:
Line 714: OleDbDataReader objReader;
Line 715: objConn.Open();
Line 716: objReader = objCmd.ExecuteReader();
Hmmm ... that's odd. Do you have Modify (Change) file system permissions on the staging server's folder? Hitting the .mdb would create that temp Access file, so if you can select you should have Write on that folder. Check that you have Modify.
Is your MDB file readonly? I am talking about the file-system attribute of the MDB file.
Seems like whatever account is utilizing the .mdb file does not have the necessary rights to the file/folder.
I've found that using an .mdb file for a website just has too many problems. You want to switch to at least SQL Express. You website will appreciate it.
ASP.NET runs under the special ASPNET or Network Service account. Mostly IIS_USERS (located in the machine)
Right click on folder containing the file to be modified by ASP user
Folder->Properties->Security->Edit->Add IIS_IUSRS (of local machine) with upto modify permission.