Classic ASP integrated with ASP.NET MVC - asp.net-mvc

I have a classic asp project and a teammate created a new functionality, but it's in asp.net mvc. I also know how to work with mvc, but I never used classic asp and mvc together.
For example, is it possible, in this classic asp project, to have a link that will redirect to a mvc page on the same project?
Thanks!!

Yes, you can have a link point to any other page you'd like regardless of technology. Likewise for a redirect. To redirect in classic ASP, use Response.Redirect

Absolutely, the pages (and that term is used lightly in the MVC side of things) can link between each other without any problems. Now, any built-in authentication or session management or anything like that will be considerably more challenging, but if all the sites need to do is link to each other then they can do this like any other two websites. The ASP pages can host manually-crafted (vs. HtmlHelper-crafted) links to the MVC actions, and can host forms that post values to the MVC actions (provided the field names line up properly).
There's nothing inherently special about the MVC actions. They're just handling HTTP GET/POST requests like anything else.

Related

ASP.NET MVC and AngularJS authorization

I am currently at the beginning process of starting a new application and am quite new to MVC and Angular. So far i have created a custom authorize attribute using asp.net MVC, this enables me to use the [Authorize] tag. Is it possible to use with an AngularJS front-end?
Any resources that will point me in the right directions would be appreciated.
AngularJs is really good for single-page-applicaitons (SPA). So just separate your front-end and back-end layers. Use Angular to implement all the views and front-end stuff. Use ASP.NET WebAPI to expose REST API for front-end (and maybe mobile) app.
A few useful links:
Angular Routing module
ASP.NET WebAPI Bearer token authorization with AngularJs
Routing in SPA with AngularJs
The answer is YES! So you can still benefit from ASP.NET MVC features like authentication and authorization etc. and still use AngularJS on the client.
I actually had the same question and after a bit of research I discovered the following.
It's true we should embrace SPAs (single page apps) but at the same time we should not just discard mature server-side frameworks such ASP.NET MVC. You can simply have a hybrid web app or mini SPA as we also call them. These web applications use normal ASP.NET MVC routing to show views and then, once the view loads you can leave all the responsabilities to AngularJS. Miguel Castro uses the term SPA silos. Plus you can benefit from AngularJS' routing as well. Miguel Castro also explains how to use them both together to get the best of server and client side. I really suggest seeing his presentation (link below).
In that way you can still benefit from ASP.NET MVC great features like Authentication, Authorization and others but still have AngularJS run your views.
I got this answer on the following locations that you definitely should check out:
Miguel Castro: AngularJS for ASP.NET MVC Developers
PluralSight - Cooper, Eames: AngularJS for .NET Developers
StackOverflow: Mixing Angular and ASP.NET MVC/Web api?
StackOverflow: ASP.NET MVC and Angular JS tipping point

What's the advantage of ASP.NET Web API to ASP.NET MVC Controller?

What's the advantage of ASP.NET Web API to ASP.NET MVC Controller?
As far as I know, IIS + WebDAV conflicts with ASP.NET Web API while using "PUT" verb[1].
We can use ASP.NET MVC Controller & JsonResult, etc. to communicate with clients, which use HTTP GET+POST and no more verb to get better compatibility, so what's the advantage of ASP.NET Web API to ASP.NET MVC?
And, ASP.NET Web API should only use the desigend teens HTTP verbs. If I'd like to develop a Web API to let a robot JUMP, but JUMP is not a standard HTTP verb. So how to design the url? http://localhost/api/robot/jump ? But it is not RESTful(RESTful urls should not contain verb).
reference:
[1] http://forums.iis.net/t/1163441.aspx
If you are asking about the difference between Asp.Net application .cs files and controllers in MVC.
We can navigate to required method in MVC depending upon requirement but this is not possible in Asp.Net web.
Always, firing the page load event will not happen.
We can return partial results/Json results/Javascript results and so on.
Unlike Asp.Net life cycle, MVC has its own page life cycle.
Regards,
Pavan.G

how to detect asp.net webforms page?

if a page contains a Viewstate in the source. Does this mean the webpage is using ASP.NET WebForms or could this also be an MVC project ?
Thanks!
Source: ASP.NET MVC and Web Forms Integration
IIS needs to be able to figure out whether a given request is an
ASP.NET MVC or a Web Forms request. Once it can figure that out, IIS
can send the request to the appropriate handler and the application
behaves as you’d expect.
check these lines from that nice article.
Caution
Watch out for ViewState! Though many parts of the ASP.NET Framework
are accessible by both Web Forms and ASP.NET MVC, the most significant
piece of the Web Forms Framework that is not supported in ASP.NET MVC
at all is ViewState. Most often, ViewState is used for a Web Forms
Page to communicate with itself, so the chances of running into
ViewState issues when cross-posting between Web Forms pages and
ASP.NET MVC controllers are slim.
However, when transitioning your Web Forms application to ASP.NET MVC,
be on the lookout for any code in your Web Forms application that
expects ViewState — the ViewState data will not exist during the
course of an ASP.NET MVC request so code that depends on it will
likely break!
There is no ViewState in MVC. So if you find a ViewState element, you can be pretty sure that it's an ASP.NET WebForms page.
Although, since ViewState is just a regular hidden input element with name/id "__VIEWSTATE", there is a slight chance, that someone added such an element (in a non-ASP.NET page) with exactly that name and id:
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="contents go here" />

WIF and ASP.NET and ASP.NET MVC on a single app

I have a web site I'd like to switch to ADFS/WIF (Windows Identity Foundation).
The web site has some ASP.NET MVC and other regular (WebForms) ASP.NET.
I've seen examples for MVC and examples for WebForms, but how can I have a blend of both flavors of ASP.NET living side by side in the same web site (same domain) which still supporting WIF for SSO in each?
WIF doesn't care whether the app. is ASP.NET or ASP MVC. Just bind your app. to ADFS using FedUtil and it will work. FedUtil just changes the web.config.
You'll lose your current authentication pages (in the sense they won't be invoked) but the rest of the app. is untouched and will work as per normal.
If your app. is not currently claims-based, you'll have to make changes to consume the claims.

Database driven asp.net MVC application

I have a CRUD application written in Classic ASP (not .net) which transfers (routes) page requests to relevant servers using a loadbalancer DLL.
It works like this:
Someone requests for www.mywebsite.com/products
There is an index.asp under folder products that redirects the request to either:
http://www1.mywebsite.com/products
or
http://www2.mywebsite.com/products
based on a loadbalancer logic.
Another scenario:
Someone requests for www.mywebsite.com/products/details
There is a index.asp under the sub folder details within the products folder that redirects the request to either:
http://www1.mywebsite.com/products/details
or
http://www2.mywebsite.com/products/details
based on loadbalancer logic
The main issue with application is whenever I include a new page, I need to create a folder and index.asp page to redirect the page.
We have a CMS database which contains the details of all pages. So I want to create an MVC application to replace the existing Classic ASP application.
But I didn't find any database driven MVC applications and I'm bit confused by routing. Do I need to create a separate route for each main folder I have or should I create a generic route for all pages.
Any help would be appreciated.
You don't have to migrate to ASP.NET MVC just for the URL rewriting.
IIS 7 does have an integrated URL rewrite module and ASP.NET 4 includes routing as well.
IIS URL Rewriting and ASP.NET Routing
URL Rewriting in ASP.NET
Anyhow, if you search e.g. on Codeplex for ASP.NET MVC projects, you'll find a lot of them which are database driven.
You don't need to create individual routes for each seperate item. Think about the concept of querystrings (?id=15&day=monday). URL rewriting is pretty much the same.
Update
I've overseen that your talking about classic ASP.
The build in URL rewrite module in IIS 7 works also fine with classic ASP. If you are having an older IIS version you need a 3rd party ISAPI rewrite module.
Anyhow, switch it to ASP.NET MVC ;)
MVC would lend itself very well to sorting your routing problem. So would ASP.NET 4.
However, the problem you have is that you don't know enough to ask a precise question. Hence your confusion with routing in MVC.
I would therefore suggest reading the nerddinners tutorial. You can get a PDF download for free. To go a step further, read Stephen Sandersons book on MVC 2 (or MVC3 in a couple of months).
If you follow the nerddinners tutorial and Stephen Sanderson's tutorial, that will give you a better idea of how it works.
In short, this is how MVC works:
In MVC, you forget about files and folders.
Instead, you have Controllers and actions. The routes map the requests to the right controller and action.
The code in the actions then decide which View to stuff full of data (from a database or wherever, it doesn't matter). The Views are just templates that are told what to do and what data to display.
The Controllers ask the Model for the data that they want.
Ie, the data access is all done in the Model, neatly separated from the User Interface.
M: Model
V: Views
C: Controller
The above is probably meaningless to you. It is a VERY different mindset to ASP classic.
If you are coming from old ASP, you will have a long hike, but it can be done. I came from Access. Anyway, read the books, follow the tutorial and see if it is for you.
When you are ready, we will still be here to help with more precise questions.
Asp.net MVC routing in your migrated application
Based on requests you've shown here you can sort everything up with just default route:
{controller}/{action}/{id}
In your case you'd have a ProductsController with all the actions you need.
Load balancing application
But having an Asp.net MVC application is just one part. This application will run on both load balanced servers. All redirecting should be done before they hit the MVC application.
If you intend to continue using the same loadbalancer DLL you could create a different Asp.net MVC application with only one route definition:
{*path}
and a single controller and action that does it all:
public Load: Controller
{
public ActionResult Balance(path)
{
// decide for web server and attach path to subdomain
}
}
This should do the trick just fine as long as the overhead of this action is very small. Otherwise your load balancing logic will become the bottleneck of your application since all requests go through this load balancer (it does that now as well so bare in mind this is no different now; never mind the authentication process on different subdomains you may be using).
Load balancing alternative
You should consider using the web farm balancing capabilities on the IIS 7 that will run your application on several web servers (because that's what your load balancing does in the first place). Search the web for web farm information. You can start with this:
http://www.iis.net/download/webfarmframework

Resources