aspx unable to locate code behind - c#

I am able to execute my application fine using the Visual Studio IDE but when I create a release package and put it on the web server it can’t seem to find the code behind. However, if I copy the bin folder (which has the dll files) from the root directory and put it into the “root/reports” directory, everything works fine. The reports directory has all the .aspx web page files. What is causing this problem and what can I do to properly fix this problem?

Since you have published your website, that means your code files were compiled into a DLL. To work properly you have to put your DLL's into the bin folder on your host server.
For Details, Check this link:
An Overview of ASP.NET Code Generation and Compilation

Related

wpf string files not found on release version but work in debug c#

I have finished a very basic application (wpf/c#). The solution is made of 3 projects:
The main project for the app
The Class Library Project to store app resources (images and txt files)
The Setup project which I use to create exe file for distribution to other
machines.
While the project works fine in debug mode when I deploy it using the Setup project and install on the computer I can access the image files from the Library Project (I can see there is a dll file for the library project in the application folder) but it fails to access the text files, complaining the path was not found. This is my very first time I completed the application and attempted to deploy it so am a bit at a loss why the setup does not provide correct references to the text files and yet it seems to work fine with image files which are located in the same library project.
Can someone point me in the right direction where to look at it to troubleshoot?
I have cleaned and rebuilt all projects in the solution. retested in debug mode (works fine). tried to search msdn and StackOverflow but I cannot find any guidance I could use or follow.
I would like to be able to display text from the text files in the released/installed application version the same way it works in debug mode. At the moment it fails to find the relevant txt files.
Finally, I have managed to crack it. Posting the answer for anyone having the same problem.
The issue here was not with the file path, even though I came up with a more clearer technique of building it, see my comments above. The problem was with the way Setup Project in VS2017 was creating a package. It is handling differently images and text files, even though both are in the same Library Project, essentially for text files I had to do the following to get it working:
Open File System in Setup Project
Create the 'Resources' Folder under 'Application Folder'
Set the 'Resource' folder 'AlwaysCopy' property to 'true'
In 'Resources' folder right-click and select Add> File...
Navigate to the folder with the files and select them all (make sure the files are setup as Resources or embedded resources)
Rebuild the Setup Project
.
So summarising I had to specifically tell Visual Studio to build the folder structure in the Application Folder during the install.
Now when I run the installer the text files are included in the package and created during standalone installation. Also included a screenshot below.

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.

About the deployment of website to IIS

I have created a website and deploy it on the IIS server. I want to change some code on the
the default.aspx. After I change the code on my own computer. I copy the default.aspx and default.aspx.cs file to the server. But seems don't work on the server. But the website work perfectly on my own computer. I would like to ask do I need to copy files other than the default.aspx and default.aspx.cs? Thank you
Depending on the project type, you need to deploy the assembly into which the changes were compiled. If this is a web application, the web project should have a corresponding DLL.
Is it a web site or a web application project in VS? It sounds from your brief description that it maybe a web application (code behind file) so once C# code has changed then you will need to compile it put the default.aspx and the newly compiled dll up on your hosting.
HTH
You also need to compile your solution and put latest dll of the project containing Default.aspx file, in server's bin directory, since you have made changes to code behind file Default.aspx.cs.
upload dll if you change code behind and aspx if you change design
load your page on browser,if nothing has change press "ctrl + f5" to clear cache and refresh your page

updating published asp.net website

I just publish an asp.net website then i made changes in its source code i added two .aspx files and then publish it again
The question is what I need to make this changes take effect on server. Do I have to replace all files or i can just add specific file?
I'm trying to add two aspx pages to the site that already exist on the server
and want to know which file i have to add beside the ordinary aspx file to take effect on site
Thanks
This depends on how you are deploying your code. Are you using the precompile option before publishing or just publishing with pre-compilation.
If you are just publishing then you can just replace the .aspx and aspx.cs files and the site will dynamically recompile.
If you have pre-compiled it then you are probably only left with .dll files and .aspx files so you would have to deploy a new copy of the .dll file for your site and the .aspx files. MSDeploy replaces the entire site by default.
If you have only changed the aspx file and not the code behind it is enough to publish those two files and on the server. If you have changed the code behind as well you also need to publish the dll files, in that case it's probably easier to replace all of the files.

Changing Output path in web project in VS2010

I have several ASP.NET web projects and their Output folder are set to "C:\Builds\[ProjectName]bin" (instead of the default "bin\" folder). This makes "F5" Debugging not working because the ASP.NET Development Server expects the "bin" folder under the project folder.
I then changed to use Local IIS Web server (http://localhost/webproject1") and manually updated the vdir physical path to my custom output path. However the VS2010 will not load the csproj because it detects the url is already mapped to a different folder location.
I know I probably shouldn't change the Output folder. But wondering if there is an easy way to workaround this? The goal is to make "F5" debugging work with custom build Output folders.
Update due to Aristos' answer:
Thanks Aristos. Unfortunately that won't solve the problem. All my projects already use the Project Reference, so all the reference dll's are correctly copied to the output folder. The reason why F5 debugging does not work is because the output folder is not the normal "bin" sub folder, but in some other path say C:\BuildsOut\Foo\bin.
It seems that in order to use F5 to debug the web project in VS2010, it has to use the default Output path "bin". If you change that, then F5 will not work and even worse your project may not even load.
Ian,
I have been frustrated by the same problem. I finally gave up and put this dirty little fix in place. I added the following to the "Post-Build" event:
copy "$(TargetDir)MyWeb.dll" "$(ProjectDir)bin"
copy "$(TargetDir)MyWeb.pdb" "$(ProjectDir)bin"
This at least lets me debug the site properly and hit my breakpoints.
You place them all on one single solution, you set as the started project your web project, and then you add on your web project the rest dll as reference (right click on web, select on menou "add reference", and automatically gets the latest version of dlls and place them on bin.
Now when you ress F5 if anyone dll project needed is automatic build it, then run the subproject with the new dll inside.
Delete all items in your bin folder for the solution in question, shut down your system and restart. This fixed it for me at least.

Categories

Resources