I am considering to do a new project in .NET.
It is maintenance of existing project. I do not have much experience with .NET projects, just some.
Client sent me source code (at least he told me that this is source code), however, I do not see any *.cs files there. It has some dll files and ascx files.
For example, default.aspx file has only one code line
<%# Page CodeBehind="default.aspx.cs" Inherits="Tere.Web._default" %>
Master page contains some view code (and not Code behind code). The first line of master page is the following:
<%# Master CodeBehind="Site.master.cs" Inherits="Tere.Web.Master.SiteMaster" %>
This is a bit confusing for me at this point.
And there is a dll called Tere.dll and Tere.Web.dll.
Can you eplain me, please, does this means that client gave me already compiled website without source code? Or maybe he has not sent me the whole project? So, what should I tell him - that this is not the source code as he thinks?
The source code would contain (at least) two files for each webpage, for example default.aspx and default.aspx.cs
When this is compiled, all the .aspx.cs files are compiled into a DLL, while the .aspx files remain as they are. This is what you've been given. You'll probably be able to make certain purely-presentational changes with this (the .aspx file contains the HTML), depending on how exactly the pages were designed. If you want to change what the site does though, you'll be out of luck - the behaviour is coded up in the .aspx.cs files which you haven't been given.
Yes looks like he's just given you the compiled code and not the code behind files that are linked to the actual pages.
Tell him that he's just supplied the files for deployment rather than the actual source.
From your description I suspect you're right: It is not the actual source. The client probably gave you the compiled code that's been deployed to the webserver.
Your client did simply not sent you the source code, but instead the compiled code (dll) and additional files for the website (aspx). The files with the source code are .vb or .cs, as you know it.
your c# or vb codes are compiled and stored in you dll files and there is no way to decompile them. When I do a project for a customer, I always send the web.config, dll files, .aspx files and all the util files.
Related
I've got a website that I published on IIS, but it seems like I've got the wrong version of source code in my dev environment.
I just need the code from 1 ascx.cs file.
Can I get to the contents of an ascx.cs file from a deployed website?
I've tried using .NET Reflector as suggested on other posts, but it seems like this tool only gives me access to my normal classes and not to the .ascx.cs files. Or am I just missing that?
EDIT:
Additional information as requested in answers.
<%# Control Language="C#" AutoEventWireup="true" CodeFile="timesheet.ascx.cs" Inherits="controls_timesheet" %>
You should use the DLL of the compiled web site to get the class that represents your .ascx.cs file.
For example, if your project is called MyWebSiteProject, you should have a MyWebSiteProject.dll on your /bin folder.
Open this DLL with .net Reflector, or http://ilspy.net/, if your control is named MyUserControl, it should be inside the namespace MyWebSiteProject.
Please double check your project's and controls namespace first.
Hope this helps, good luck :)
I have a site that I'm about to publish and I want to know how to set it so it would not deploy the code behind?
Essentially i'm trying to find the difference between an aspx file that calls the code behind .cs file and another that calls a dll that's in the BIN directory?
The below explanation from the Microsoft ASP.NET documentation discusses the difference between explicit and automatic compilation.
In order for the ASP.NET engine to service a request for this page,
the page's code portion (the WebPage.aspx.cs file) must first be
compiled. This compilation can happen explicitly or automatically.
With explicit compilation you need to copy up the assemblies in the
Bin folder, but you do not need to copy up the ASP.NET pages' code
portions (the WebPage.aspx.cs files).
With automatic compilation you need to copy up the code portion files
so that the code is present and can be compiled automatically when the
page is visited.
When you publish a web project (from Visual Studio), the source code from code behind (.aspx.cs files) will be converted to a binary dll file named as [YourWebProject].dll and will be copied under the "bin" folder.
In Brief:
In an ASP.net website with a code-behind, at what point are the *.cs files compiled?
Context:
A colleague who has since left, deployed a website with a .cs code-behind to a shared server. I have made a small change to a .cs file, which I should expect to reflect on one of the pages but it has not yet appeared. I have restarted the application pool, however I am loathe to reset IIS on the server as there are couple of other teams' apps which might be be in use on the same server.
This applies to Web Application projects as opposed to Web Site projects, which are CodeFile by default, and don't allow changing the build action...
In ASP.NET Web Applications you have two methods of deploying your pages; CodeFile and CodeBehind. By default pages will always use CodeBehind but you can change this.
CodeBehind
CodeBehind compiles your .cs file into the .dll file in your bin folder at compile/build time, and then you deploy that to your web server. There is no need to deploy the .cs file to your web server. If you do, it will just sit there being unused.
To configure a page with CodeBehind, ensure that:
The page directive in your .aspx file has CodeBehind="your.aspx.cs"
The properties of the .cs and .designer.cs files in solution explorer have a build-action of compile.
CodeFile
This causes ASP.NET to compile the .cs file on-the-fly on the server. This means that your .cs file needs to be deployed to the web server. It also means that your .cs file will not be compiled at compile/build time and therefore not built into your .dll in the bin folder.
Key advantage
With CodeFile, You can make changes to the .cs file and deploy just that file to see the changes on your production web server. No need to re-deploy. No need to recycle the app pool. This can be very useful in a lot of situations.
To configure a page with CodeFile, ensure that all of the following are met:
The page directive in your .aspx file has CodeFile="your.aspx.cs"
The properties of the .cs file in solution explorer have a build-action of content
The properties of the .designer.cs file in solution explorer have a build-action of none.
Notes
Intellisense doesn't like working when pages are set up with
CodeFile (you can change to CodeBehind whilst coding and then change back for deployment, though).
If you change from CodeBehind to CodeFile, then always do a
rebuild and re-deploy (and vice versa). This is because when the page was CodeBehind,
the .cs was compiled into the .dll in the bin folder, and will
remain there when you change to CodeFile. The CodeFile will be
compiled on-the-fly and you will get the same code/classes defined in
the .dll and in the on-the-fly compiled code, which will lead to
runtime errors.
For the setup I use, the .cs files are compiled when building the project. This means it is the .dlls in the bin that need to change, not the .cs files directly.
The .aspx files can change at any time, but I think you need to rebuild the project in order for the code behind to take effect.
I have replaced singular .dlls before without any problem (though it's not good practice).
Apparently what you have done should work.
Check if Cacheing has been implemented.
Otherwise publish the code and deploy the dll, instead of .cs file. I would recommend to test in staging server before you go live.
Assume there is a asp.net 4.0 web application and it has a default.aspx and default.aspx.cs files in it. After I build the project, a dll that is named of the project created in the bin folder. So what the dll contains ? All code behind files compiled versions ?
If the aspx files still refers its CodeBehind file like below, then does the dll used for this aspx file or still code behind is valid to run the project ?
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication3._Default" %>
In a Web Application, all your C# code is contained within the DLLs in the bin directory. There are a couple of exceptions, such as DLLs that you rely on that live in the GAC, for example. Using a web application ( your question says this is what you are using ), you do not need to deploy your *.cs code behind files.
A Web Site is different. Changes are detected and recompiled on the fly. You'll need to include your C# files code-behind files when creating a Web Site type project.
ASP.NET Web Site or ASP.NET Web Application?
A DLL is a library that contains code and data that can be used by more than one program at the same time:
What is a DLL?
Code-behind refers to code for your ASP.NET page that is contained within a separate class file. This allows a clean separation of your HTML from your presentation logic:
ASP.NET Code-Behind Model Overview
The code gets compiled into the assembly produced by your web project. You can change its name and default namespace as part of project options.
As I understood it, the ASPX file is only used IF the project is marked as being updatable, otherwise it is just a placeholder file.
Since all files in a web project are compiled into single assembly, then does this assembly maintain a directory structure? For example, if a file in a root directory references a file in a subdirectory, then how could this reference still be valid when the two files get compiled into same assembly?
Assume a web project has the directory structure shown below.
Since all of web project’s ASPX files get compiled into a single assembly WebProject1.dll, how is this assembly able to record/memorize the directory structure?
Thus, when you deploy WebProject1.dll to a web server and user makes a request for http://WebProject1/some_SubDir/default.aspx, how will WebProject1.dll be able to figure out which Page to render?
WebProject1\SubDir (where WebProject1 is a root directory)
WebProject1 -- contains several ASPX files
WebProject1\SubDir -- contains a file default1.aspx.
When we deploy the Web project, must we create the same directory structure on a web server (WebProject1\SubDir), even though we won’t put any ASPX files into those directories?
I assume that on Web server WebProject1.dll should be placed into the Bin directory?
thanx
EDIT:
Only the sourcecode is compiled into the assembly, you still need to upload the aspx files into a matching directory on the server.
My book says that when using Web project all web code is compiled into single assembly. I thought “all code” includes aspx files?!
Links are maintained between the page and it's code behind file through a class declaration which by default is in a namespace that matches the directory structure
So if I add a new aspx page via Project --> Add New Item, and store this aspx page in a subdirectory named Hey, then this page will reside in namespace WebProject1.Hey?!
But how do I do add new item into a subdirectory, since Project --> Add New Item doesn’t give me an option to browse and choose a directory I wish to save it in, but instead automatically creates aspx file in a root directory?
The relative path is kept when the compiler generate the dll.
I’m not sure I know what relative path you’re referring to?
thanx
Only the sourcecode is compiled into the assembly, you still need to upload the aspx files into a matching directory on the server. For example you project in Visual Studio may look like the following:
WebProject1 (The root project)
|
|- some_SubDir (A physical directory inside the project)
|
|-default1.aspx
|-default1.aspx.cs (assuming a C# project)
Once you have compiled the web app you'll need to upload the following to the server:
WebProject1 (The root directory for your website)
|
|-bin (The binary directory created by the build)
|
|-WebProject1.dll (The compiled source code of the web app)
|-some_SubDir
|
|-default1.aspx (The file that will map to the URL www.websitename.com/some_subdir/default1.aspx)
Compiled resources (non-sourcecode files that are compiled and stored inside the assembly) are different issue that are addressed in your other question
Edited to add direct answers to the questions:
Not all files are compiled into the assembly, only source code files are. Links are maintained between the page and it's code behind file through a class declaration which by default is in a namespace that matches the directory structure, but it doesn't have to be.
Your default1.aspx file will have in the header something like:
The inherits line tells the webserver that when a user requests this page it should be processed in conjunction with the source code that defines that class, which it will find inside the compiled assembly. The combination of the physical aspx file and the compiled class will generate standard html which is then passed back to the client.
Yes, you need to create the same directory structure, but you are required to put the aspx files in there.
Yes
(can someone please edit this if they know how to get the list items to number correctly, please?)
All those path information will be embedded as Meta Data/resource file, so, you can deploy it safely to the server. The relative path is kept when the compiler generate the dll.
I suggest you use Reflector to open the dll, and you can get a much more deeper understanding what is inside dll.
Notice how some_Subdir/default1.apsx has a 'Inherits' key/value pair in the page declaration?
What this means is that when you make a request for that resource IIS goes 'Ah ha! Asp.Net needs to handle this request! Hey asp.net please return me some html to send down'
Asp.net parses that aspx file and creates a proxy class on the fly that inherits from WebProject1.some_Subdir._Default1. This proxy class then parses out the control tree and html, and kicks off the page life cycle (this is overly simplified, and I'm sure I've missed some details).
So the WebProject1.dll is just the actual C# / VB of your web app, but in concert with the asp.net worker process and the markup you can render html back to a client.