SCENARIO: A developer at work has created an three-tier ASP.NET Web Application which plugs into the company website, however the rest of the site was done as an ASP.NET Website. For clearity, his portion used Web Application (compiled into single .dll) and the rest of the site is WebSite (seperate .dlls). I do not wish to recompile the website every time a change is made to a page.
QUESTION: Is it possible to convert a Web Application
to a Website without rewriting the entire application?
TRIED:
Created WebSite and copied & pasted files over
Changed'CodeBehind' to 'CodeFile'
Deleted .designer.cs from pages and controls
Checked References
Ok - assuming you have a backup, this is how I would tackle it:
Delete the csproj file
From within Windows Explorer, delete any designer.cs files
Still in Explorer, create an App_Code folder at the root of the site
Find any *.cs files that aren't code behinds (eg., .ascx.cs or .aspx.cs) and move them into the App_Code folder
Open in Visual Studio as Web Site project
Verify .NET FX version
Change CodeBehind= to CodeFile= in any .aspx or .ascx files
Readd any 3rd party references
There's some potential complications around Global.asax, ASHX handlers (need to be inline) and referencing pages and controls. You'll have to deal with those manually, I'm afraid - but if it's a smallish effort, it should be easily doable.
Related
Please could you explain this concept I can't seem to get my head around...
Within a C# ASP.Net web application written in Visual Studio, I have added an XML file which is being read by the code. To add the file, I physically copied it into the relevant folder within my web application, and then in Visual Studio added a reference to it within an "xml" folder, which is in my "_resources" folder.
The C# code is accessing the XML file in the following way:
using System.Web.Hosting;
string path = HostingEnvironment.MapPath(WebConfigurationManager.AppSettings["XMLFilePath"]);
The XMLFilePath value is set in the Web.config file as follows:
<add key="XMLFilePath" value="~/_resources/xml/anXMLFile.xml"/>
The file is successfully accessed when I'm testing locally. I then check it in, (into my source control system), then the application builds automatically on the web server. Then comes the problem... the file cannot be found and is not in the folder I would expect it to be in on the web server. If the automatic build is happening correctly, (which is quite a big if right now), am I right to assume that, as the file is present within the web application, it would then be present on the web server?
Right click the xml in Solution Explorer, go to Properties and make sure its Build Action is Content
We are working on a website project which contains around 1130 pages. After compilation, all the .aspx.cs files are converted into AppCode DLLs that has random names.
Whenever there are any changes in single .aspx.cs file[like a hotfix], we have to recompile and deploy the entire project on the application host.
We want to update only those files that have been changed and not the entire package.
One of a solution we are aware is that, converting Website to Web application; but we cannot implement that change at this stage of the project.
Is there any other way to find an efficient solution for this?
Yup. Talking in Visual Studio 2010:
While publishing the website, Select the option: 'Use Fixed naming and single page assemblies', Also select 'Allow this precompiled site to be updateable'.
After website is published. Go to the published folder. Open any aspx page (not the dll or .cs).. Note the dll name in page attribute under inherits attribute. Than using ftp or any other way to upload, copy or upload tht dll under bin to your website.
Also, you can create a doc or txt file to list all Dll names with respective paths to your file to easily know which dll to upload next time if there is any change.
Hope it helps.
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.
We are publishing our website using VS10
1) While publishing the website Localy, only aspx files are grouped together in the published folder and that web is working fine in the local IIS server.
2)though .cs files are not in the published folder all the events are working well in Local iis server
3)what I am doing..... I am coping that published web folder and uploaded it to the web server.
4)but now it showing an error for every event I calling????
5) how can I tackle this problem??
6) For security reason I don't want to upload my code behind files to web server?? I want to hide my programing logic how can I do this ????
7) when I am uploading my web with both the .cs and aspx files it working well but I don't want to do this??
You need to publish your website it will generate dll put that instead of putting .cs files. This codeproject article explains how to do it.
You do not need to copy all of the files. You only need to upload the .ASPX file and the Bin folder which will contain the compiled logic in a DLL named YourProject.DLL and also any other references that are required. The .CS files containing your actual code are not required on the server as they have been compiled into the DLL.
With JavaScript you cannot hide this from the user because it is needed on the client-side. However, you should save all of your JavaScript into a .JS file and include on the page. At least it makes it less obvious to someone viewing the source of your page.
Publishing your web site will do the job.
Please read How to: Publish Web Sites (Visual Studio)
and
ASP.NET Web Site Project Deployment Overview
I am using a SharedAssemblyInfo file which seems to be a 'standard' technique:
http://blogs.msdn.com/jjameson/archive/2009/04/03/shared-assembly-info-in-visual-studio-projects.aspx
I put the SharedAssemblyInfo.cs file into my web application because with web site projects I cannnot 'add files as a link'.
But now I need to add a second web project to the solution and obviously the SharedAssemblyInfo file cannot be within both projects.
How do I get round this problem without having duplicate SharedAssemblyInfo files?
One way to solve this problem from within a web site as opposed to a web project is via your source control provider.
If you are using Visual Source Safe you can "share" the file to both projects (folders) and not branch. If you are using subversion 1.6 you can use a single file "externals" property. See this page for info.
In the case of Team Foundation Server, you can look at this codeplex article. I don't have any experience with TFS, but I think in the case of a SharedAssembly.cs the branch and merge solution would work fine.
This means you will have to check the file in in one location and check it out in the other location for the change to take effect. However, have the AssemblyInfo out of sync during the development process probably won't break anything.
Is it a web site or a a web project? With a web project the linked file should work fine... although personally I'd rather keep them separate and update them through my build script.