What files do I upload in a C# Web API project? - c#

** Dumb questions alert **
I created my first Web API project. I would like to test it on my web host, but I can't figure out what files to upload. I tried to upload everything from the HelloWorld folder, but I get a 403 "Access is denied" error when I attempt to access the files.
Once I upload the folders/files, how do I access them? Do I have to navigate to the Root > Views > Home > ... ?
Folder Structure
HelloWorld
HelloWorld
_UpgradeReport_Files
1 css, 1 xslt, 4 pngs
HelloWorld
All of my folders and files
This is what I tried to upload
packages
A lot of ASP and JQuery folders
Thank you for your help.

I think you have two separate problems here: knowing what files to deploy and getting the permissions correct so that you can access them.
In general, the files you will need to deploy are all of your static files (images, CSS, Javascript, HTML), any .cshtml/.aspx/.ascx/.asax files, and Web.config. However, the easiest (and best) way to know what files to deploy is to use Visual Studio's publishing mechanism. Go to Build->Publish, and publish to a local directory. Open that directory, and you'll see all the files you need to deploy.
As far as the second problem, that's more complicated. The solution depends on the version of IIS, but the basic upshot is that you need to give the correct user access permissions to your file. Depending on your version of IIS and how it's confusing, it will either be IUSR, IIS_IUSRS, or NETWORK SERVICE. Try Googling for "file permissions IIS ".

Related

File or directory not found although it exists and the path is correct

I have a problem - I cannot find my file when I open it using http://localhost:49652/.well-known/acme-challenge/FfI7Xeq7_QH5R5pCd3LhAkU4k3nOqBz9mNbvJ9EwMoQ although it exists and the path is correct.
I use ASP.NET C#, OS: Windows Server 2012 And IIS 8.0.
And error:
Help me... Please!
I want to forward you to an other question: What file extensions are blocked by default in IIS
The issue is that IIS has a configuration, how to handle requested files.
Depending on the extension, there have to be done different actions: While resources like .txt or .jpg files are just sent into the network as they are stored on the disk, other files like .aspx or .asmx have to be parsed, executed in dotnet and then the output have to be sent etc.
Other extensions like .dll or .exe are blocked by default, I think.
The problem is, that your files do not have any extension, so for this directory you have to configure that IIS should pass through all of the files.
Found another usefull link to microsoft: https://learn.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/fileextensions/

Visual Studio 2015 Working Directory not being applied to C# project

So this is something that I expected to be simple, but I am not sure what is going wrong.
I am working on a C#, ASP.NET Web API project, and I am trying to set a content path to some folder in the solution's root directory.
For some reason, no matter what I set the Working directory option to under Properties > Debug, printing out Directory.CurrentDirectory() in my applications startup logic is always the default (somewhere in the bin directory for that project). I tried using $(SolutionDir), but found that is not supported in C#. I then tried some relative paths and absolute paths but nothing is working.
Am I missing something here? Is this setting just not used for C# projects or does it have something to do with it being a ASP.NET project? I found other questions on here asking how to set the current directory, but the answers were to use exactly the setting I have been using.
I know I can technically just change where the build executable is located, but that seems like an ugly work-around when the logic of the application already uses the working directory.
EDIT: Some more details in response to some comments.
So the premise of this project is it is a C# Web API that serves as a backend for an angular app. The angular app is built separately into a zip file which is then stored in the resources of the C# program. Upon running, the files are extracted and served on localhost for client machines. When the program is run in debug mode, however, it just sets a root content path and serves the raw files for the angular frontend. My goal here is to remove some manual configuration in debug mode as to where the angular frontend is is on disk. It is checked into the root of the solution directory, so I am trying to set the current working directory for debugging to the solution directory, and then the program will just be able to work normally when being debugged from Visual Studio.
I hope that isn't confusing things further.

Deploying a Click-Once Application

I am trying to deploy my application to be downloaded from my website. It is written in .NET 4.0. I think I have it on my server but I am not sure? When I try to deploy it again I receive this message.
Here is the setting I have for publishing.
And as you can see from the website, nothing is there.
Im not the best with web stuff, so my question is what the heck am i missing.
More Info
So. I published it to the wrong location, but i found it.
Currently, your folder http://www.theinsanityelement.com/insanepin/download/ is empty. You have entered ftp://neshmet.dreamhost.com/ as target location - I guess this is mapped to http://www.theinsanityelement.com/ root. That means you should enter
ftp://neshmet.dreamhost.com/insanepin/download/
as publish folder location, or whatever path is mapped to your target URL. Then you can access the download page from
http://www.theinsanityelement.com/insanepin/download/publish.htm
You could also change the "Deployment Web Page" name to index.htm, then the following would also work:
http://www.theinsanityelement.com/insanepin/download/

App_Code and server

I'm having a "tiny" issue with my App_Code folders.
I'm learning ASP.NET and, therefore, ordered a webserver with the support of ASP.NET 4.0. I'm using Visual Web Developer to program my webpages. When I upload my website to this webserver everything runs fine.
However, if I then add another web project to my server, my App_Code folder gets all messy. The server wants all my class files in the App_Code folder in the root. Is there any way I can create subdirectories in my App_Code folder or something to keep my projects organized or am I missing the point here?
You should take a look at codeSubDirectories in the web.config
Alright I found a solution to my problem. Although most of your answers might work aswell, this proved to be the best in my case. I created a subdomain and threw all files into that folder and it worked fine.
You should try to avoid using the App_Code folder for your own stuff, especially if you're using a web application project.
Whenever you convert a website to a web application project, the process actually renames your existing App_Code directory to Old_App_Code.
See Here, even though this is specific to converting .net 2.0 apps, I believe it still holds true in 4.0 since converting a 4.0 app does the same thing.:
VERY, VERY IMPORTANT: Because ASP.NET 2.0 tries to dynamically compile any classes it finds under the /App_Code directory of an application at runtime, you explictly DO NOT want to store classes that you compile as part of your VS 2005 Web Application Project under an "app_code" folder. If you do this, then the class will get compiled twice -- once as part of the VS 2005 Web Application Project assembly, and then again at runtime by ASP.NET. The result will most likely be a "could not load type" runtime exception -- caused because you have duplicate type names in your application. Instead, you should store your class files in any other directory of your project other than one named "app_code". This will be handled automatically by the "Convert to Web Applicaiton" command. This command will rename the folder Old_App_Code.
If you have access to a hosting control panel it's probably best to configure your hosting environment with a virtual folder for your second website and run it from the sub folder, e.g. www.example.com/project-b. The first site can still be running in the root folder, e.g. www.example.com.
So both sites will essentially be isolated from each other (just like they are now isolated as two separate projects in Visual Web Developer Express). And both sites have their own App_Code folder (and web.config file).
If you don't have access to a configuration panel, most hosting providers are willing to add a virtual folder for you, since it's really not a special requirement.
The virtual folder should show up as a regular folder in your FTP folder, usually inside the www or wwwroot folder. Now you can copy your project files into that folder.
Take care to use root-relative paths for URLs in your second project, so all links will work even when the website is run from the subfolder. Root-relative URLs look like this:
<asp:HyperLink runat="server" NavigateUrl="~/Default.aspx" />
<asp:Image runat="server" NavigateUrl="~/images/logo.png" />
This will automatically go to www.example.com/project-b/Default.aspx and www.example.com/project-b/images/logo.png when the website is deployed in the virtual folder.
If you need to re-use code from one site in the other, it's typically best to move such code into a separate Class Library project type, and then add a reference to that project to each website project (right-click the website project, choose Add reference..., then select the Projects tab and select the Class Library project).

How to Backup a webservice?

The problem is I reinstalled my computer and the backup didn't work so now all my sourcecode is gone... But my webservice is still running on a webserver.
When I upload the new website the old site will be deleted, so how can i backup the webservice and make it a part of my new website?
In the bin folder of the webserver there is some strange name files like App_web_cjcpmkr8.dll,
can I just download these files and .asmx files? Isnt there then missing a link between the files? How can I see which .asmx files uses which .dll files?
Unfortunately they're all compiled- depending on your site's config, there will be either one assembly per page or per directory. You can download all the DLLs and decompile them through reflector- the decompiled class names should help you match them up with the corresponding markup, but you'll still have some reconstructive surgery to do.
The magic link between the asmx and the dlls lies in the name of the bin folder. IIS will automatically look for dlls in this folder. You should be able to deploy your web service on a new web server by just copying the files. I recommend that you try to set up a copy of the service on a new web server, before you delete anything.
If this is critical data get a service to try and get your files back. If not then moving forward invest in an online backup solution / source control utility.
This will save you tons of time when this happens again. I use source control on a remote server combined with a subscription to Carbonite locally to ensure that I don't lose that precious data; both the data checked in and the data that I'm currently working on. It's Iike $45 a year and well worth it.
As for your data I'm sorry that you've lost it. I'm sure you’re not the first to have this happen.

Categories

Resources