how to edit a file in an online aspx site? - asp.net

I'm very new to asp.net ( but an aged PHP developer) ..
I'm now in a situation where I should do some small modification in an online aspx script(using vb.net).
I downloaded the whole site and opened it in visual studio, all the modification I had to do is to make a redirect to another external page after succesful login,I determined the place where I should do my modification inside a file named login.aspx.vb , and added this line in it:
Response.Redirect("My URL Here")
And then uploaded only the modified file again, to get no change at all.
I even tried to modify the success msg that appear after successful login and re-uploaded it to find no change at all ( still showing the old message)
Is there some step I'm missing before uploading the page?

You will need to compile the project, and if using visual studios you can just hit ctrl shift B and it will build the entire solution. Visual studio detects which project in the solution has changed and will compile it. Then do as the other answerer says and upload the .dll file which is a container of your compiled code that will be referenced by the host you upload it to when there is a request for it. (A container is a definite over simplification for more details check:
What is a dll?

In ASP.NET there are two types of projects.
Web application project
Web site project
In the first case, when you edit a .vb file you need to compile it with Visual Studio and upload the generated .dll file created in the bin folder.
In the second case you can edit the .vb files and upload them and IIS will compile them.
Based on what you wrote, you are in the first case. In that case you need to have the project / solution files to make any modifications in the .vb files. If you don't have access to those files you could inject some code in the .aspx or .ascx files.
For example:
<%
Dim flag As Boolean = false
// Write some code to set the flag
If (flag) Then
Response.Redirect("~/default.aspx")
End If
%>
Using <%....%> you can write code to execute when the page starts to render. This is a bad practice since because it has poor performance since the code is parsed and executed at runtime, while the code in .cs files is already compiled.
But if you don't have the project files you could do minor changes with this hacky approach.
Edit: If you are in the first scenario, you need to build the project and then upload its .dll file which is in the /bin folder. For any changes in the code files you upload only the .dll. If you change the .aspx, .ascx, etc files you need to upload those as well

Related

Modifying ASPX.CS file has no effect

One of my colleagues maintains a legacy ASP.NET site. Today she bumped into a strange problem:
There is an ASPX page, which throws an exception.
If she deletes the line of the ASPX.CS file which throws the exception, the exception remains (with the same call stack). I'm sure she modified the very same file the calls stack refers to.
If she renames the ASPX.CS file, the server says the file is missing.
If she restarts the server after modifying the ASPX.CS, the exception remains.
If she modifies other ASPX.CS files, she gets the expected effect.
She doesn't compile the page into DLL.
AFAIK IIS should recompile the file when its content changes (MSDN), but this mechanism doesn't work in this case. What should we do? Thanks for your help in advance.
Check to see if the website is a website or web application. Web applications compile all the code behind into DLLs and place them into the 'bin' folder. In order to make changes to the code available, you would have to 'build' the application in VS.
If it is not a compiled web application, then she should check to see if the front end page is pointing to the correct code behind page. Sometimes if you manually copy and rename files, this piece could be left pointing to the original page, not the new .cs file.

You are attempting to open a precompiled Web site

I have a website developed in asp.net. Files have both aspx pages and codebehind files. When I try to open it in Visual studio 2010, I get this message:
---------------------------
Microsoft Visual Studio
---------------------------
You are attempting to open a precompiled Web site. You can view the site, but changes might cause the Web site to stop functioning. To modify a site, it is recommended that you edit the files in the original Web site, precompile the site, and then publish it again.
Do you wish to continue and open this Web site?
---------------------------
Yes No
How to open this website for editting ?
I know this is WAY late but it might be of use to subsequent readers.
First off, Martuza Kabul is wrong. You only need 2 files, the .aspx/.ascx/.master and the relevant .cs (this means .aspx.cs/.ascx.cs/.master.cs)
What has most likely happened here is that somebody has compiled the site and the DLLs are now lying in the bin folder. (If you are as lucky as i am, they're also in source control..)
Here's what you need to do:
Delete the PrecompiledApp.config file
Delete all the non library .dll files in your bin folder (mine were WebApp_122141Xas or something like that, these are compiled codebehind files.)
Look at the first line of your .aspx / .ascx pages - In that control tag - in there is an "inherits" attribute... you will see it has 2 values, delete the 2nd one.
In that same control tag, notice that the Codefile attribute is missing. Add it and point it to the correct codebehind file.
That should be it. Hope this helps somebody.
You have to have CS file to edit the website. I assume that you are trying to open a website which was published earlier using precompiled option.
Pls post type of files in your website for further information.

Publish only edited page in asp.net

Whenever I update a small part of my website I have to upload whole website again.
If i upload only edited part it throw me exception.
The way I upload my website:
For example if I have 4 pages (home, register, about me, contact me) and if I update home.aspx, I publish whole website in a local address, and then I compress it with zip format and upload it manually.
Is it possible to publish only updated part?
It is not possible to publish only a part of website, but what you can do is to choose Single-File Assembly build option ,by this you can get single assembly for your page.so intead of updating whole application you can update only the pages you change
read more
What I always do when publish ASP.Net Webform project, I complate it with two steps. Maybe this way suitable for you.
When you use publishing tool on visual studio by selecting Build menu -> Publish, you can choose "File System" as "Publish Method", type your "Target Location", and select "Replace matching files with local copies". It mean the project will publish modified files only.
After publishing have done, Open defined "Target Location" using windows explore and sort by "Modified Date" and just copy newer modified files for each directory recursively to your server.
If you build the website pages into dll. You can not published only the aspx. there are many other dll and compiled files in bin folder, we don't know which matches which aspx.
If you only edited the "view", i mean, the html and markup part of <%%> code, and no code behind (.aspx.cs) change, you can published only this aspx. But remember to set website as updatable in the publish dialog.
I suggest you to compile the aspx into one dll. according to #Buzz 's answer. Then, your aspx files would be only an empty file. All you need to do is upload only one dll to the bin folder.

How asp.net application works?

I am quite new to .NET development and I am just wondering how does it work?
My undermentioned points are:
While developing ASP.NET application, under the project we have files like:
pagename.aspx
pagename.aspx.cs
pagename.asp.desiger.cs
After adding certain functionality to pagename.aspx page, assuming I have the development required web application (this is not my concern, what is developed)
Now I'm going to deploy this application, I use web deployment MSI which creates the required files in the one folder called folderdelopyed.
This folder contains the files required to support this application but interesting does not contain pagename.aspx.cs and pagename.aspx.designer.cs files.
My question is if folderdelopyed does not contain .cs file, then how does it work to run the segment of code which I have written in this file called PageName.aspx.cs?
The code in your cs files gets compiled into a dll.
For Web Application projects this is one dll
For Web Site projects, this is a dll per page.
All of the code is now in the dll's in the bin folder of the website.
You can use a tool like ILSpy (http://wiki.sharpdevelop.net/ILSpy.ashx) to look inside the dll's and see your code.
In the old days, for classic ASP, the script used to be embedded in your page - a mix of code and HTML, and was interpreted at runtime.
I like the new way more :-)
ASP.NET code is compiled into Dynamic-link library files, also known as DLL files.
The code you write in your code behind, which is the files with .cs extension, is compiled and put into whole new file, with .dll extension - and that file is copied to the server, to the BIN folder of your site.
Depending on what project type you choose, it's possible to have several DLL files for the web application, changing in every build - see dash's answer for more details.
On every .aspx page you have referece to what DLL file to use, as the very first line. For example:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="pagename.aspx.cs" Inherits="MyNameSpace.pagename" %>
In this example, the Inherits part determines what DLL to use. How? By the namespace, which is also the name of the DLL file.
When the above .aspx is requested by a browser, the .NET engine will go to the BIN folder, look for MyNameSpace.dll and in there look for class called pagename that inherits from the base Page class - all the rest is typical life cycle of ASP.NET page.
let me to say you something more Amazing.
you can hide your aspx file too.and put their content in to dll as same as your cs file put in dll.
you can make k aspx that just contain an address to the ddl file and no html body :D
that was greate!!! not only you can hide your cs file, you can hide you aspx file too :D

How do you update an ASP.NET web application?

Simple question. If you have a compiled and published ASP.NET web application running on a server and you need to update, say, a line in one of the codebehind files. Do you shut down the entire site, republish, then load the site back up? Or do you publish straight to your live site with users still using it?
For myself, place an app.offline app_offline.htm file into the site, then overwrite the entire website with the latest published build.
there are a few options when building a site -> one dll for the site or one per page. if u just updated one line in a code behind, and you have chosen the build option for one per page, then you can just copy/paste that new page dll.
i don't like that method personally. I find it simple to app_offline.htm the site.
If it is a single file and a simple site that uses that app_code folder to store the code behinds, I simply xcopy up the new files. If I use http expiration headers I may need to do some better scheduling to make sure things like javascript files and css sheets match the rest of the site that was updated.
For emergency patches:
If its just a codebehind file, I copy the entire /bin/ out and replace all DLL's (mostly out of habit)
If its an aspx, I just copy the aspx.
For actual deployments, I have an automated system that checks out the code from source control, builds a clean release build, takes the site offline, and then robocopies it out to the deployment target. Its a one click process (Thanks CruiseControl!).

Resources