Why do we use 'code behind' in WCF? - asp.net

First of all, what are the advantages of Code Behind and Code Beside? I have searched on the internet and found that we use Code Beside in web sites and in ASP and Code Behind while creating WCF. What is the reason behind this?
Thanks in advance

Because WCF service is not a web page. In ASP.NET WebForms you define markup in your web page and code related to markup. When the page is compiled initialization code related to markup is generated and merged with your code to form a single class handling the web page.
In WCF the "markup" contains just declarations. It is just support file for IIS processing which will tell web server which service factory and service type must be used to handle incoming call. Information from markup is not related to your service class and there is no code merge - the code behind service class is complete implementation of the service and can be used even without the markup file which is not true for code beside web pages.

Related

Hiding http file extension without using MVC controller

I am using basic asp.net web application project template, because I want to move away from MVC into SPA.
Most of my pages will just be basic html files that will interact with the server through ajax calls. That said I want to hide the .html extension, but I don't want to create controllers just to hide this, which is too much of an overkill.
Of another note, I am using Azure as well, so setting this up on IIS directly is not going to work, as I would not be able to scale the administration nicely.
So how can I hide the html extensions without such a heavy layer as an MVC controller?
This sounds like a job for Url Routing
Url Routing allows you to intercept a request and then determine how to service it. It is how MVC does it and has many other useful benefits. If the router isn't able to service it, it falls back to the default ASP.NET pipeline processing, and then IIS.

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

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

Can I merge data and template on server side in .net?

My project is a .net web application containing some boxes on a page with their own data. to load each of the boxes we called a web method (in a web service). we use this approach to load boxes separately(suppose a box has paging within itself and we don't want it causes loading the whole page). my question is about first loading of the page that causes all web methods call and page load slowly. I want to make html of page on server side for first loading of the page and when user open the web page for first time, we send just the made html. I mean similar to merging json data to jtemplate but in server side. or similar what mvc architecture does. or...??? Any Idea ?
Multiple calls to the webservice might slow down the page load. It would be better if we make a single call to the webservice and the service return a dto with data for the boxes in your page.
The simplest way would be to invoke all web methods on the server side as web service calls and send the combined html to the browser.
Better way would be to invoke actual web method implementation (i.e. calling the method code instead of web service invocation) and then combine the html.

Sending asynchronous request on clicking a sharepoint web part button control

I am new to this whole sharepoint and aspx programming. I have developed a sharepoint web part that has a button control. The onclick event is mapped to a method in my web part code. When I click the button the whole page reloads and the web part is rendered again. Is there a way to prevent this reloading of the page? Is there a way to call the function method in the background? Something similar to AJAX.
Thanks,
Jagannath
You can use Ajax, it just requires some sharepoint configuration. Here are a few posts to get you started:
http://weblogs.asp.net/jan/archive/2007/02/26/using-the-ajax-control-toolkit-in-sharepoint.aspx
http://sharepoint.microsoft.com/blogs/mike/Lists/Posts/Post.aspx?ID=3
Ajax or SilverLight are your only two options for Async operations without a page refresh.
Once you know the tricks needed to get SharePoint and ASP.NET AJAX to work together it's not that difficult.
Here are the steps required:
Ensure the ASP.NET AJAX Extensions are installed on all the front-end web servers (this is not required if you are using .NET 3.5 as the Extensions are included in the Framework)
Update the Web.config file for the SharePoint Application to support ASP.NET AJAX
Ensure any page that is going to use AJAX has a ScriptManager
Use an UpdatePanel or a client-side service call to get updated data and re-render the Web Part
This blog post has some resources from a talk I did on the subject at TechEd Barcelona 2008. These resources should give you the information you need to get started.
http://msmvps.com/blogs/windsor/archive/2008/11/13/teched-emea-resources-and-demos-integrating-asp-net-ajax-with-sharepoint-2007.aspx

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