ASP.NET does not seem to need a ASPX page - c#

I was working with other Dev team (I'm mostly a winform Dev) and I saw the following:
Our APP is an ASP.NET App. This application(solution) has a webfrom project
and also several VB dlls(for business and data layers).
Recently one ASPX page changed(VB code behind),
And also a dll which this page was using.(VB dll data layer)
So solution was built successfully, without errors.
When they were deploying this change to the webserver they only copied the VB DLL for data layer and the webproject dll. So only 2 dll copied.
My question is why we didn't need to copy ASPX files to webserver?

This might help you to understand the issue.
Aspx pages converts to dlls.
http://forums.asp.net/t/1909746.aspx/1?File+updating+Issue+on+hosting+provider+server+

OK Here are results of my re-search so far which I hope the future viewer of this post finds usefull.
If you change a Webpage HTML part you Do need to copy the ASPX page to the server. In this case copying the web project DLL won't reflect HTML changes.
If you only change the code behind and "do not touch" the HTML then you can just copy the DLL to the sever. The Website clearly does not care about code behind VB or C# files.
Note that in my option the above case is highly a bad idea, as now we have a ASPX.VB or ASPX.CS file(s) sitting on the web server which have a different code with the dll. Therefore for consistency purposes all of these files should be copied together.

Related

.Net Core Razor Pages - Server Side Include

I'm unable to get server side includes (*.html files) working in a .net core razor pages web application. I've made sure to have the appropriate handler in my applicationhost.config, but I'm thinking there's a different issue here. Any help is appreciated.
Why am I doing this? I have multiple web applications sharing the server side include files (for navigation bar, footer, head content, etc..). Each of these different applications may be of different Microsoft web architecture. Our goal is to move everything to .net core, but we have lingering web forms projects to deal with along the way.
I have performed a work around by taking the SSI file contents and using #Html.Raw to serve up the content. This is probably wrong also.
I went ahead and changed the file extension of the html files into cshtml which allowed me to treat these files as partial views. I'm using a prebuild event to copy these files from a shared solution folder into my project Pages/Shared/ssi folder. I also copy those partials into wwwroot/ssi for the other applications to use via SSI. Eventually all of the apps will use the partial views instead.
The problem with this solution is that it is not necessarily clear that all edits need to happen in the shared solution folder instead of directly in the project, but the documentation for the project will address this. I tried using linked files, but only one link to a specific file can be made in a project.
Not a perfect solution (to the problem), but this not a perfect website either.

In VS 2019 - How to regenerate code-behind and designer files from an existing aspx page

I imported in my project Web c# an aspx page, for example, mypage.aspx, with HTML code. This page is very simple.
All I want is to generate the 2 files (in IDE) aspx.cs and designer.cs (mypage.aspx.cs and mypage.aspx.designer.cs).
I tried "Convert to web project" functionality but it does not work.
Any idea, please?
Of course, I read several solutions on this site but none worked (with vs 2019).
If there is no actual code in the original code-behind file then it's pretty easy to do. Create a new page of the same name. Then just copy and paste the markup from the original, taking care to leave the newly-created page directive as is.
If there was logic in your original code-behind then you're out of luck. You might try decompiling the original DLL and try to re-create the original code that way.

ASP.NET Webforms Deployment & Markup Changes

In ASP.NET Web Forms, I know when the C# changes the primary DLL also needs to be deployed. I also know when the markup (.aspx, .master) changes where new controls are added, the primary DLL needs to be deployed.
What about when the markup (.aspx, .master) changes and no controls are added? Can the .aspx or .master page be changed without deploying the associated DLL? I see 2 scenarios that may have different answers:
Simple markup changes (e.g. HTML, CSS. JS)
Dynamic changes in the markup (e.g. add <%=Page.ResolveUrl("~/test.aspx") %>)
**Note:
Ideally I'd deploy the whole app on any change, but I'm dealing with a fragile legacy app.
.aspx or .master pages be changed without deploying the associated DLL provided changed contents/controls don't change the interaction with the server-side code. For example in Home.aspx you add a paragraph <p>Sometext</p> deploy just Home.aspx, application would keep working.
On the other hand, obviously, if any control name is changed/event is added, you need to deploy associated DLL (after necessary updates).
I hope this helps!

How to deploy a single user control which has changes to the cs file (ascx.cs)

I have a user control (UserControl1.ascx) and I made changes to Its cs file.
That UserControl1.ascx is being used by two or more aspx files using LoadControl.
I don't want to deploy the whole web project dll as this is a fix for a critical issue in a part of the web app and doesn't affect the whole web app.
Updating changes to the single web form code behind is easily done. However not sure about the single user control deployment. Any help is appreciated.
it's a bit of a hack but you could move the code from the .ascx.cs file to the .ascx file and remove the inherits attribute. Asp.net first checks the referenced class in the inherit attribute. So I think this should allow you to update the web application without updating the .dll files. I didn't test this however, but I think it could be a viable option.
If you just deploy the updated user control (ascx) form and the relevant DLL, the only discernible delay will be the load time of the first hit after deployment, which you can do yourself with a browser refresh.

How to deploy an ASP.NET project so that there is no code in the .aspx files?

I've recently become the maintainer of an ASP.NET web project. In the course of deploying some changes, we noticed that at some point the way the project deploys has changed. The project is a web application project. Currently, when I "Publish" it to my local machine, I can open the various .aspx files and see some code--a little ASP, mostly JavaScript, but the majority of the code seems to be compiled into a .dll.
What we would like is to build and deploy this application so that there is no code in the .aspx files--this is how it used to work, before the previous dev stopped maintaining it. There should be no code in the .aspx files at all, just a reference to the compiled .dll files.
Does anyone know what I'm talking about and how to set it up?
EDIT If it helps, it looks like the older version of the app just had text in the .aspx files that said "This is a marker file generated by the precompilation tool, and should not be deleted!" That is what I'm going for.
If you want to do this for your Website just Pre-compile your project for deployment only. You can check out the exact steps in this MSDN article
This will move all the codebehind files into the .dll and create .aspx.compiled files as pointers to the compiled versions in the .dll. Sounds like thats what was being done before.
The code shouldn't be visible from the client's browser.
Any code that in a code-behind will get compiled to a .dll which the pages in the application would reference. The actual code-behind files shouldn't get published with the .aspx files.
.NET code within the .aspx files shouldn't be visible on the client-side because it has no use on the client-side. It should be executed on the server-side to render HTML output to the client. If the .NET code is visible on the client-side in this case, it means the server isn't executing it and the site is essentially broken.
JavaScript code, of course, needs to be visible on the client-side. There are ways to obfuscate it, but the browser needs to see it in order to execute it. So in this case that code should be developed with the full understanding that it is publicly visible and nothing proprietary or compromising should be included in it.
JavaScript code has to exist on the client side, so that has to be on the server. Inline ASP code? I'd look into rewriting that into .NET.
In order to achieve no code in the .aspx files you need to write all the code in the code behind. You use the asp.net events in the life cycle to perform the generation of client code. For example, dynamically generated HTML and javascript could be generated in the Page_Load and written out as a Response. Any asp.net that you may use needs to be dynamically generated in the code behind with everything else.
You will still push HTML and javascript to the client, but all the code will be in assemblies/dll's except the header info in the aspx pages. I have only done this in the context of a web service ( RESTful) where I pushed out XML to an iPhone for consumption. Doing it for a full website may prove to be quite cumbersome.
It doesn't make sense to do this if the concern is security. Moving the code to an assembly is not much more secure than the aspx page. If the concern is to remain concise, I suggest moving to ASP.NET MVC 3.

Categories

Resources