Same Component in both asp.net, asp.net MVC and Classic ASP - asp.net

I have a big website/application coded in Classic ASP, ASP.NET and ASP.NET MVC.
I have a menu on top with a lot of HTML CSS JS, and some conifiguration (visible or not ...)
and lot of dynamic links.
So the problem is when i have to update the menu i have to update 3 files, one Include in Classic ASP, one ASCX user control in asp.net and one Partial view in asp.NET MVC
I hate code duplication, so is it possible to use only one component ?
I heared about Com but i have no idea where to start.
Thanks for help
Edit : I am thinking know to use a .net Object, that can generate a string containing all the html that i need and then put it in the views MVC and in the asp.net pages
But how to use it in Classic ASP?

There's nothing stopping you using a webapi controller to expose this functionality; the webapi controller would return json or xml menu structure to the client browser this in turn would be rendered using by injection of the json over into the browser DOM and styled using CSS.
Classic ASP and MVC ASP.NET would use the same javascript and css.

I'm also working in a legacy application that is very much similar to your case, how bad the life is :(
I'll go for XML/XSLT in your case.
I'll create an XML file that contains all the menu details and use XSLT to generate HTML from XML. I can easily use the XML and XSLT in all the three technologies. So every time you need a change you have to change either the XML or XSLT file.
You can even create a simple .NET component that uses the XML/XSLT approach which could be easily used in ASP.NET Web Forms, ASP.NET MVC (in custom view engine?) and in classic asp as well (you have to register).

Guess, you can make an action method in asp.net MVC to render the dynamic menu and do AJAX load from the javascript in every part of the site?
UPDATE:
You can make an HTTP GET request in classic ASP to the aforementioned ASP.NET MVC handler, and cache results if its not very dynamic. Anyway it should be pretty fast if its within the same server. I suppose, request will look like in this answer

Related

Static pages in ASP.NET MVC

Suppose that your ASP.NET MVC website contains a handful of dynamic pages and a big amount of static pages that of course need the Login & Register link on the top right corner. How do you handle this?
We have converted the HTML pages to ASPX and introduced the ASP.NET code to display the user name but I am not sure that it's the best approach. In addition we needed to move static pages to a different folder to avoid collision with MVC routing.
Is this the best that can be done?
Thanks.
ASP.NET MVC and Web Forms can live together with no problem. If your approach is working out for you then it should be fine.
Also see the below article. It might help :
Integrating ASP.NET MVC 3 into existing upgraded ASP.NET 4 Web Forms applications
http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx
I believe as long you implement Donut caching within the ASP.Net pages you can get similar performance as static html pages.
If you use IIS Form Athentication for your site static content can be accessed only if the user is authenticated, so you can mantain HTML files and do not convert them in ASPX, but you need to add some javascript to hide the login link and display username (you can check the auth cookie of IIS or create your custom cookie).
Have you considered some client side script that loads the username/password section you need?
You could have it load a view and inject it into a div. Then you have a single point to maintain for all the static content.

How to convert the existing ASP.NET server control into MVC

I have an ASP.NET custom server control that inherits from the Panel control. It adds its own JavaScript and styles to the page using ScriptManager. Now some users ask me if I can update it so they can use it in MVC. What can be done here? Any references, links, etc would be greatly appreciated.
What can be done here?
Sorry to disappoint you but a total rewrite and re-engineering is required. ASP.NET MVC is an entire different pattern than classic WebForms which relied on server side controls and (may God forbid) ScriptManagers. Depending on what this control is doing and the functionality it exposes there might be different ways to migrate it to MVC. One way would be to use custom Html helpers along with custom jQuery plugins.

ASP.NET Web Pages (with Razor syntax) Life Cycle

I could only find this but at some point it talks about the IsPostback property so I think it might be for the ASP.NET Web Forms.
Is there any information relative to the ASP.NET Web Pages Life Cycle?
Update: When I use some JavaScript, how it is related with the Life Cycle of an IController instance?
Maybe you mean the life cycle of the controller. If so you should also find this useful
The Life And Times of an ASP.NET MVC Controller
JavaScript code is always executed when th page is served to the client. This is true regardless of the technology you use. All serverside code is already executed when the page is served to the client therefore JavaScript executes after it.
ASP.NET Web Page is a view engine (with razor syntax), just like other view engines, It only do render your data + template to html.
It is usually used with ASP.NET MVC. If you want to know how request and response work in ASP.NET MVC, you can read these articles ASP.NET MVC Architecture, Routing and Filtering

ASP.Net MVC View within WebForms Application

I am adding functionality to an ASP.Net webforms application and we've decided that new development will be done MVC with a view to move all functionality over eventually.
Obviously, MVC and WebForms play together rather nicely when it comes to accessing an MVC action via a URL. However, I'd like to display the MVC view within an existing tab (telerik) control on a WebForm page. This view will be using js/css file so that will need to be considered also.
Well I'd use jquery/js to load the tab dynamically on page load / select tab. If add a js function to the required handler you can fire an ajaxGet to retrieve the html from your MVC action URL.
If needed I can get some sample code. Are you using jQuery in your ASP.Net app or MSAJAX ??
Cheers
ian

barebone asp.net

Is it possible to do Web form without using server control or set runat attribute on html control? How do you call the code behind function?
You can't call codebehind functions without a runat="server" tag at a minimum. If you created a Web Service instead, you could create a pure html/javascript page that interacted with the server through AJAX. These are your only two options to use ASP.Net as far as I know.
Yes, it is possible to do this. The form with runat server is only needed if you use postbacks and server controls.
If you do not use server controls you should be able to add forms to the page that POST to other pages (it can even post to itself). In your page_load you will be restricted to using the normal request.form and request.querystring to retrieve form values, but you should be able to call other methods on the page.
If you are familiar with classic ASP, you can do the same thing with asp.net.
Also, take a look at the asp.net MVC framework (http://www.asp.net/mvc). It allows you to use asp.net without using webforms.
You can use a HTTPHandler for barebones ASP.NET.
You won't have a markup file, you'll just have a class that runs and exposes you to HttpContext for writing out to the HTTP stream.
http://msdn.microsoft.com/en-us/library/f3ff8w4a(VS.71).aspx
In fact, HttpHandlers are the building blocks of all .NET web frameworks.

Resources