Are ASP.NET mobile views only for ASP.NET MVC? or can they be used in plain ASP.NET as well? - asp.net

I know in ASP.NET MVC you can have mobile views and do things like Index.mobile.cshtml and _Layout.mobile.cshtml and the server knows to serve these views/pages to mobile devices rather than Index.cshtml and _Layout.cshtml, but can this also be done in plain ASP.NET websites (not using MVC)?
Note : I am using razor syntax in the plain ASP.NET website.
Thanks in advance.
-- Lee
UPDATE :
To clarify, I am aware of the various browser detection methods. My question is specifically about whether mobile views in the form Index.mobile.cshtml are available in plain ASP.NET.
UPDATE (Functionality now included in ASP.NET latest release announced 18th February 2013) :
Talk of the devil.. this is now possible in a recent release..
Scroll down the page to the heading 'ASP.NET Web Forms Enhancements'
http://weblogs.asp.net/scottgu/archive/2013/02/18/announcing-release-of-asp-net-and-web-tools-2012-2-update.aspx

Take a look at this, brief description of mobile support for ASP.NET Web Forms:
How To: Add Mobile Pages to Your ASP.NET Web Forms / MVC Application

My understanding is that the alternate view modes support native to MVC4 is a result of the WebPages2 used by MVC, and is currently only used within MVC to resolve locating Views via the View Engine (combination of VirtualPathProvider and DisplayModeProvider). This is because views served up via MVC and requests via the URI do not map to physical locations on the server to serve up files from. ASP.NET on the other hand serves up files directly based off of the URI, and does not depend on a virtual path provider the way MVC does.
My guess would be that ASP.NET does not support automatically serving up alternate files based off of the same framework that MVC uses. That being said, I'm sure it would be possible to derive an implementation based off of the of the logic of VirtualPathProviderViewEngine that could achieve a similar result with ASP.NET, however I know of no implementation that does this currently. Best suggestion would be to see if you can find usages of DisplayModeProvider and see if anything pops up.
I'm not an expert so feel free keep looking but I thought I would offer what I can.

So I have come to the conclusion that this is not built in functionality in plain ASP.NET.
Though there are (IMO less elegant) alternatives.
Are ASP.NET mobile views only for ASP.NET MVC? Yes.
Update : This may be possible in latest release
http://weblogs.asp.net/scottgu/archive/2013/02/18/announcing-release-of-asp-net-and-web-tools-2012-2-update.aspx
-- Lee

Related

What is the difference between ASP .NET Web Forms Applcation and ASP .NET Web Forms Site

I need to write a simple app which will work in a cloud where I can store data about clients and it will be avaiable from Windows and Android and I assume it has to be a website.
What is the difference between ASP .NET Web Forms Applcation and ASP .NET Web Forms Site? Which one should I use?
Web Form Site is nothing more than previously called Website projects where you work with webpages which is just small php like (with Razor/aspx) script files which render as html.
Webform is more like a component oriented framework. Web Form Site or WebSite should only be used for small projects or if the project needs to be compile in C#/VB both language. Also if you want to put your all source code in web-server then it can be used. On contrary with WebForm application you don't need to put code base files to run the projects - you'd be better off only putting scripting .aspx files.
This has been explained in detail in the following question:
ASP.NET Web Site or ASP.NET Web Application?
Also, you can check out the differences between the two here:
MSDN
Regarding your first question if your app is native or hybrid then you need REST(WebApi in .net world) which any app can access natively regardless of the device and will meet your needs of the "cloud".
If you what you want is a website instead that is "viewable" by mobile devices you may want to make your website "responsive" and you can look at various bootstraps templates that can help you with that.
Regarding your second question I think it has no bearing nor it will make any difference in creating a mobile app which project type you use.

How to integrate GWT with ASP.NET MVC3?

I already have an ASP.NET MVC3 website, using Razor as the Views engine.
Is it possible to create the UI using GWT and invoke it as a View in my MVC3 website?
How is it done correctly?
Note: I know it easier to use JS API's such as JQuery or Google Closure to build UI in ASP.NET MVC3, but currently GWT is a requirement for the project.
The question is whether you want to go down the multi-page or the single-page road.
GWT is a toolkit which helps you create single page web-applications where the backend only serves as a datasource. This is a SOUI (Service Oriented User Interface) approach.
A single host page serves the GWT client application and you deal with flow synchronization and other user interface pattern (MVP) on the client side.
If you go down this road, you will probably not use any of ASP.NET MVC3's advanced features (specifically the model controller view part).
However it is also possible to use GWT in a multi-page setup where the backend takes care of the "flow synchronization" and you embed GWT as widgets in the corresponding views/pages.
You end up with small GWT apps for each host page/MVC view. You won't get all the optimizations in code-reuse because each host page will be a separate GWT app and thus shared code will be downloaded multiple times.
Regarding your specific question and the technical aspects of ASP.NET MVC3 and Razor:
I can't really comment on that because I don't have experience with ASP.NET MVC3. But in general GWT apps can be embedded in any web-page by simple including the nocache.js bootstrap file (if you want history support also embed the hidden iFrame).
See here for more details.
Note: this project could be also of interest to you.

ASP.NET MVC alongside Web Forms in the same web app?

Has anyone successfully deployed ASP.NET MVC alongside Web Forms in the same application in a production environment? Were there any conflicts or gotchas you faced while doing so?
Is it really as easy as shown here in practice? What about if you run a MVC using the Razor view engine alongside Web Forms?
Mvc is build on top of asp.net as is webforms, so yes it's easy.
Done it couple of times for conversion purposes
Maybe this url's could help you:
http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx
and
http://www.hanselman.com/blog/PlugInHybridsASPNETWebFormsAndASPMVCAndASPNETDynamicDataSideBySide.aspx
One gotcha is don't put your WebForms inside the Views folder. I haven't get figured how to make MVC leave those paths alone. None of the ignore routing instructions seems to work in this case and the WebForms throw 404s.
Other than that WebForms works perfectly fine alongside MVC since MVC2.
Has anyone successfully deployed ASP.NET MVC alongside Web Forms in
the same application in a production environment?
I never mixed ASP.NET MVC and classic WebForms in the same application. I make them run in separate applications and communicate between them with standard HTTP techniques (query string parameters, form posts, cookies, ...).
Is it really as easy as shown here in practice?
Yes, it is as easy as that.
Check out scott hanselmans AddMvc3ToWebForms nuget package. I am using it and its working pretty great. I am using it to gradually convert my web forms app to mvc
I've spent a lot of time over the past few months on this. Here are my observations.
The good/easy
- Getting Webforms to call into MVC controllers
- It was remarkably easy to stand up a new MVC3 project and drop Webforms pages into it.
- I was able to move my <pages><controls></controls></pages> section into the /pages directory in a new web.config there
The dirty/difficult
Regarding the GUID
Please note that the GUID has to be added at the front of the line for some reason... everytime I tried it failed. Until I stumbled on a post that insisted it be the before the others.
also I don't know what the difference is but I have a different GUID working... {E53F8FEA-EAE0-44A6-8774-FFD645390401}
getting the landing page to be Webforms caused ALL kinds of snags.
getting jQuery intellisense to play nicely with T4MVC
this is what I did to address that
#if (System.Diagnostics.Debugger.IsAttached)
{
<script src="../../Scripts/Mvc3/jquery-1.7-vsdoc.js" type="text/javascript"></script> #* intellisense! *#
#Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_1_7_js)
#Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_unobtrusive_ajax_js)
}
else
{
#Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_1_7_min_js)
#Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_unobtrusive_ajax_min_js)
}
Recommendations:
Use T4MVC in ALL cases even if you are pure webforms. The elimination of magic strings for static content (.js,.css, images, specifying templates) is outstanding.
and if you have any part of your build process compiling views then you get compile-time safety on any of those links.

How is the best method to generate a url with ASP.NET?

I will apprecaite your help in this topic.
I need to build a site with friendly urls using url rewriting in order to improve SEO positioning.
I've been searching torought web and finally pointing to this two main options :
asp .NET with isapi extension
asp .NET mvc
however, I got no experience on both items so I need you to help me to kwow further about this two technologies and to take the right decision for my needs.
Thanks
There are much bigger concerns than just URL setup when making this choice. You're talking about two completely different architectures for building your web pages.
You should make the decision on how you want to build your application, what skillsets you have available in your developers, etc. Both approaches will be able to handle the URLs that you need to generate for SEO considerations.
For public facing websites, I would personally choose ASP.Net MVC, because I find the development cycle shorter, more productive, more flexible and more maintainable than an ASP.Net webforms application.
Assuming you have a host/server that can run ASP.NET MVC (i.e. one that has the .NET Framework 3.5 Service Pack 1 installed on it), you can use the Routing Engine (System.Web.Routing) from ASP.NET MVC in a web forms environment, Phil Haack has a good updated walkthough at "Using Routing With WebForms".
There's also "How to: Use Routing with Web Forms" on MSDN.
Unlike an ISAPI filter, this enables you to use the routing engine to generate your internal links as well as responding to well formed links from outside.
I agree with womp. But there is one advantage i see in Asp.Net webforms that Asp.Net Mvc doesn't have: Rich Client Iteraction controls. Everything in Mvc in View layer is simple and functionality need to be build from scratch.
alexserver - at the same time of course, the fit between mvc and jquery is an overwhelming reason to abandon the rich clinet controls. that way, you can literally get your designer and/or a jquery UI expert to work on the view portions in isolation whilst you craft the model and controllers.

Can "classic" ASP.NET pages and Microsoft MVC coexist in the same web application?

I'm thinking about trying out MVC later today for a new app we're starting up, but I'm curious if it's an all or nothing thing or if I can still party like it's 2006 with viewstate and other crutches at the same time...
Yes you can have your webforms pages and MVC views mixed in a single web application project. This could be useful if you have an application that is already built and you want to migrate your app from webforms to mvc.
You need to make sure that none of your webforms pages go in the 'Views' directory in a standard ASP.NET MVC application though. Pages (or views) in the 'Views' directory can't be requested directly through the url.
If you are starting an application from scratch, there would be very little benefit to mixing the two.
Yes. MVC is just a different implementation of the IHttpHandler interface so both classic ASP.NET and ASP.NET MVC pages can coexist in the same app.
As you've probably noticed with the above answers, yes this is very possible to do.
I've actually had to do this on my current project. I was able to get approval to add MVC to our application, but only in the administration section (to limit the risk of affecting current members coming to our site).
The biggest problem I had was converting my Web Site to a Web Application, but once that was done, things were pretty straight forward adding MVC side-by-side our classic code-behind web pages.
The trick for me was to make my MVC pages look as similar as possible to my code-behind pages so the transition looked as seamless as possible.
I am currently working on a new project. While I would like to go down the MVC route all the way, some of the project requirements don't allow me.
One of those requirements is to have a grouping grid from the client-side. Personally have chosen the Telerik Rad-Grid. While they may be in the process of supporting MVC they are not there as yet.
So this means that I have to have a hybrid solution. for the time being until RadGrid fully supports MVC.
While we are in this transition period I think that there will be may more hybrid projects out there until the support of the Third Party Controls catches up.
Regards
Nathan
You'll need to make sure your MVC routes don't conflict with your Web Forms pages so that requests for a .aspx page don't get routed to a controller action as a parameter etc.
See this blog post by Phil Haack for details on how to avoid this.
Yes, it is very much possible for MVC pages to coexist with asp.net web forms. I implemented that in my existing asp.net application for adding new features. We need to make sure of referring the MVC DLLs, registering routing tables for URL routing and configuring the assemblies and namespaces in Web.config file.
If you're mixing MVC with other methodologies you're not really getting the benefit out of it. The point of MVC is to allow you to decrease coupling and increase cohesion, and if only half of your code is doing that, then the other half is inevitably going to restrain your development cycle.
So, I guess while it's possible, I don't think it's worth it. Go all the way or don't go at all.

Resources