System.IO.CreateDirectory or System.IO.File.Create won't work from a web service when navigating to the app remotely. It works locally.
Environment:
- .Net 4.5, Asp.Net, C#
- VS 2012
Remote:
- Windows 08 R2
- IIS 7
- App Pool (.Net 4.0, Integrated)
Process:
The web service is in the project and is used in jQuery .ajax call with url: 'Services.asmx/UploadFile'. The WS method creates the folder chain (if not found) and writes the file.
The file upload works perfectly fine locally in VS.
It also works perfectly when published on a remote server and navigating to it locally on the server (thru RDC) either by localhost/{app} or by http://{ip}/{app}. The folder chain is created and file is written.
However, it does not work when navigating to it normally.
I'm pretty sure it's a user permission issue but I've exhausted all options. I've assigned modify rights on the app folder in wwwroot to "NETWORK SERVICE" and even though I'm sure unnecessarily to "IIS_IUSRS", "IUSR", "LOCAL SERVICE", "NETWORK" and none have helped! I just keep getting status 500 when I navigate to it normally. But it has always worked locally as mentioned above once I gave it "NETWORK SERVICE" modify rights.
Publishing a basic test app with a button and CreateDirectory in code-behind on the same server worked after assigning modify rights to "NETWORK SERVICE" on the app folder in wwwroot.
The create directory code in the web service is:
[WebMethod]
public void UploadFile()
{
string _userId = HttpContext.Current.Request.Form["userId"];
HttpPostedFile _file = HttpContext.Current.Request.Files["Filedata"];
string _uploadsFolder = Server.MapPath(String.Format(ConfigurationManager.AppSettings["FileUploadPath"], _userId, "Temp"));
if (!Directory.Exists(_uploadsFolder)) Directory.CreateDirectory(_uploadsFolder);
FileStream _fileStream = File.Create(Path.Combine(_uploadsFolder, _file.FileName));
_file.InputStream.CopyTo(_fileStream);
_fileStream.Close();
}
FileUploadPath in web.config is
When it works, it works with or without the "~/" in the path. And when it doesn't work, it's the same, with or without, it won't work.
Related
We have an app that updates a gitlab project and pushes/commits to master. When I run locally, the program runs fine. When I run on the application hosted server (not the gitlab server), I get a 404 "Project not found".
It's not the private access token, we just made a new one
I can sign in to gitlab on our app hosted server and find the project
I verified the account can push straight to master
There is no xdt transformation on the config files
I logged into the account on the app hosted server and hit the project via the same api url.
Here is the codified url:
RestRequest fileExists = new RestRequest(
$#"api/v4/projects/{project.id}/repository/files/{action.file_path.Replace("/", "%2F")}?ref=master&private_token={ConfigurationManager.AppSettings["JiraPrivateKey"]}",
Method.GET);
I'm almost thinking it's some sort of server setting, but I would think that I would get the 404 when I tried the api url in the browser.
After thinking about it, since I use the ConfigurationManager, I had to copy by .exe.config file to the server and not just the exe itself. After dragging the config and the exe over. It worked. :-(
I have a shared drive on my local network \hostname\shared\resource. I have mounted the drive programattically from within the Asp.net core web application in the startup.cs file.
app.UseStaticFiles();
app.UseFileServer(new FileServerOptions{
FileProvider = new
PhysicalFileProvider(#"\\TS3410D618\NickFlicks\Movies"),
RequestPath = new PathString("/Movies"),
EnableDirectoryBrowsing = false
});
This works perfectly when I run it with IIS express(debugging), however, when I deploy it to my local IIS on the same machine the application fails to start with the error:
Application startup exception: System.ArgumentException: The directory name
\\TS3410D618\NickFlicks\MoviePosters\ is invalid.
This is a valid UNC path and can be reached from everywhere I have tried on my windows 10 machine. As I mentioned everything is on the same machine except for the shared drive.
As a side note I can mount a virtual drive from within IIS sucessfully, so IIS can access the fileshare without any issues.
I'm not sure what I am doing wrong here, any help would be greatly appreciated.
I could never get this to work because I couldn't find a way to create an Active Directory with Windows 10 or to modify the user permissions for the UNC file share for the user used by IIS. Basically, I just installed Ubuntu server with Nginx as the reverse proxy and everything worked fine once I set up the permissions properly, which was very straight forward.
I'm trying to upload a basic web application from visual studio on Windows 7 to an IIS environment on Windows Server 2007.
Though launching it from IIS displays the Login page, trying to navigate past it to the main menu returns this error:
Server Error in Application "PARKING/PARKING ASSIGNMENTS WEB"Internet Information Services 7.0
Error Summary
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. Detailed Error Information
Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x80070002
Requested URL http://localhost:81/Parking Assignments Web/Home
Physical Path C:\ParkingAssignmentsWeb\Home
Logon Method Anonymous
Logon User Anonymous
Most likely causes:
•The directory or file specified does not exist on the Web server.
•The URL contains a typographical error.
•A custom filter or module, such as URLScan, restricts access to the file.
Things you can try:
•Create the content on the Web server.
•Review the browser URL.
•Create a tracing rule to track failed requests for this HTTP status code and see which module is calling SetStatus. For more information about creating a tracing rule for failed requests, click here.
Links and More InformationThis error means that the file or directory does not exist on the server. Create the file or directory and try the request again.
View more information »
This is the code I used for navigation:
Response.Redirect("Home.aspx");
Why would this navigation work on Visual Studio but not on IIS?
UPDATE: I tried the variations of the Redirect command you guys showed me but all of them gave a 404 error, which leads me to believe that the problem isn't with the command but with something else. Any idea what?
It treats Home.aspx as a relative path.
Use it like:
Response.Redirect("/Home.aspx");
when you deploy to IIS a different web server is being used. Visual studio uses a web server with limited options and in most cases but not all an application should run without changes when deployed to IIS on windows server.
Things to check
Verify that the folder structure on your workstation looks the same as the folder structure deployed to the server.
check permissions on the folders accessed by IIS on the web server
Response.Redirect("Home.aspx"); assumes that the file is in the same directory as the page that is invoking the transfer
add a more complete path either ("/home.aspx") or ("/folder/home.aspx") where folder is the actual folder name that contains the .aspx file
Please try:
Response.Redirect("~/Parking Assignments Web/Home.aspx");
or
Response.Redirect("~/Parking Assignments Web/Home");
I am facing issue in my web application which is made in asp.net. I have host the application on IIS server.and I am going to upload excel file to port data in database from application.when i uploading from locally from server itself its working fine but i when i try to uploading using public ip or outside then my application redirect to IIS root folder can any one tell me whats is the issue.
this could be an permission issue on your web.config, file and folder permission or maybe a missing reference to correct folder.
Web.config
What is the authentication ? Do you allow Anonymous access. I understand that you can upload fine if you open the side from localhost from the server itself. Did you try to open the side with public ip from the server itself ?
Application Pool in IIS
Look for the "Identify" configuration and set this to "ApplicationPoolIdentify"
File Permission
Look for the folder and ensure that the "IIS_IUSERS" got write permissions
Code Try to sepecify the correct path using the server.MapPath()
Dim myPath As String = Server.MapPath("foldername") & "\" & "filename.csv"
I have a Published ASP .NET MVC web project running in IIS within a VMWare Virtual Machine(Windows 7). I am able to log in to the VM and navigate across the application from within the VM itself, but all content files(JS, CSS) are returning a 404 error.
i.e : 'http://localhost/WebProject/Home/Index' loads fine, but, 'http://localhost/WebProject/Scripts/Home/IndexScript.js' within that page throws a 404 error.
Any ideas?
If you can access IIS on your VMWare it means that your IIS works fine and VMWare too but there some settings which restrict access to some urls or url is wrong.
Are you sure that you have file at path /Scripts/Home/IndexScript.js'
If yes then check
IIS not serving static content (css/js/images, etc) 404
IIS7 returns 404 on some static files, not others