If I have a library that uses .NET component licensing (such as DevArt's dotconnect) with the new Razor view engine, do I need to produce a special App_Licenses.dll for Razor to work?
I can see you already got the official answer in their forums:
http://www.devart.com/forums/viewtopic.php?t=20815&sid=0cdf252bc73af673032cccc6f7443659
If ASP.NET source files will be
compiled at server on user request,
you should create a special assembly
App_Licenses.dll in the Bin directory
of your site:
http://www.devart.com/dotconnect/universal/docs/licensing.html#asp.
We have not tested our product with
Razor view engine. If you encounter
any difficulties, please contact us.
Based on that answer, I think you might not need it if you pre-compile your Razor views
See Compile Views in ASP.NET MVC (and Notes on Building Razor Views).
Related
I am reasonably familiar with C# desktop development and am very familiar with Rails, so ASP.NET MVC makes sense to me. However, I have a more lightweight site that I want to build in a manner more akin to dropping a bunch of .php files into a hierarchy of directories and having them be served up as just HTML files run through a pre-processor. (A full MVC stack and architecture seems like overkill for what is basically a brochure site.)
I believe it is possible to do this in ASP.NET (I remember the single .aspx pages approach from back in the day), but I'm not sure what this programming model is called in order to search for info on it--I can only find references to MVC and "web forms" in newer documentation.
I also would like to use pieces that are more popularly used in MVC, but in this more simple page-based model. For example, I would like to use Razor templates (with layouts and partials) and to access a single Model object that is shared across a number of templates.
I would appreciate any advice, or info on how to find documentation on using ASP.NET in this way.
The ASP.NET Web Pages framework supports web applications built using the Web Site project type* as well as Razor layouts and partials. It does not support strongly type models in the same way as MVC. However. that doesn't prevent you from taking a strongly typed approach to Web Pages development. The mechanism for passing data to partials is via the dynamic Page property (similar to ViewBag) which requires casting to get Intellisense support. Web Pages also lacks any kind of Model Binding support.
*This is the ASP.NET project type that does not require pre-compilation before deployment (as opposed to the Web Application project type). Web Forms apps can be built using either project type, but ASP.NET MVC apps can only be built using the Web Applications project type.
I have several websites and these website share several components. It was quite easy with classic ASP.NET WebControls ascx. I created several such controls, put into one dll library and I reference these libraries from these websites via namespace.elements runat=server...
But I don't know how to do it after I have upgraded to ASP.NET MVC. I can put model and cotroller class into dll.
But how should I put and reuse Views into dll?
I suppose that Views are not compiled into dll, if I can change the View without recompiling the dll.
EDITS:
I would prefer some standard solution over third party. The last solution for me is to use StringBuilder instead of ViewEngine.
I've been using Razor Generator for several years to store reusable MVC views and helpers in separate .dll.
Razor Generator "is a Custom Tool for Visual Studio that allows processing Razor files at design time instead of runtime, allowing them to be built into an assembly for simpler reuse and distribution."
Installation instructions
It’s on the VS extension gallery, so install
it from there. It’s called “Razor Generator” (not to be confused with
“Razor Single File Generator for MVC”).
It is quite simple to use:
Usage in an MVC app
Install the 'RazorGenerator.Mvc' package, which registers a special
view engine
Go to an MVC Razor view's property and set the Custom tool to RazorGenerator
Optionally specify a value for Custom Tool Namespace to specify a namespace for the generated file. The project namespace is used by
default.
Optionally specify one of the generators in the first line of your Razor file. A generator declaration line looks like this: #*
Generator: MvcHelper *# . If you don't specify this, a generator is
picked based on convention (e.g. files under Views are treated as
MvcViews)
You'll see a generated .cs file under the .cshtml file, which will be used at runtime instead of the .cshtml file
You can also go to the nuget Package Manager Console and run 'Enable-RazorGenerator' to enable the Custom Tool on all the views.
And to cause all the views to be regenerated, go to the nuget Package Manager Console and run 'Redo-RazorGenerator'. This is
useful when you update the generator package and it needs to
generate different code.
MVC project should be chosen for class library in order to support intellisense and other useful features.
Usage in a View Library
If you need to create a separate library for your precompiled MVC
views, the best approach is to actually create an MVC project for
that library, instead of a library project. You'll never actually run
it as an Mvc app, but the fact that it comes with the right set of
config files allows intellisense and other things to work a lot
better than in a library project.
You can then add a reference to that 'MVC View project' from your real
MVC app.
And note that you need to install the 'RazorGenerator.Mvc' package
into the library, not the main MVC app.
Programming ASP.NET MVC 4 written by Jess Chadwick tells that
In the ASP.NET Web Forms world, you can achieve this by creating user
controls or custom controls that can be compiled into standalone
assemblies. These assemblies can be distributed across projects,
thereby enabling their reuse across projects.
The Web Forms view
engine offers the ViewUserControl class, which can be leveraged to
create such components for the MVC framework. The Razor view engine in
ASP.NET MVC, however, does not offer any such method out of the box.
and suggests using Razor Single File Generator visual studio extension, another one but the similar to Razor Generator approach.
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
I've developed a most reusable ASP.Net WebUserControl for our company's web applications. I'm now going to make it as a redistributable DLL according to this msdn topic. Since the WebUserControl comes with some JavaScript(s), CSS(s) as well as images. I'm asking how can I bundle them all together to form a single DLL?
Our development environment is Visual Studio 2008, .Net Framework 3.5
Please kindly advise!
Thanks!
William
You could bundle the non source code parts in a resource file and reference them through there in your ASP.NET code. You could add to the default resource file (.resx) or add your own..
I haven't actually tried this but I think you could embed the user controls, JS files, etc into the output assembly of your reusable library project. Basically in the Properties dialog you'd set the "Build Action" to "Embedded Resource" for those files instead of "Content".
Then the consuming application would implement and register a VirtualPathProvider to tell ASP.NET to look for user controls inside the assembly.
Here's a similar question dealing with loading MVC Views from a DLL, same idea: Using VirtualPathProvider to load ASP.NET MVC views from DLLs
And this: http://www.wynia.org/wordpress/2008/12/aspnet-mvc-plugins/
What is the syntax/analogue for Assembly Directive http://msdn.microsoft.com/en-us/library/a7c375wt(VS.71).aspx in MVC 3.0 Razor
On MVC View i have this:
<%# Assembly Name="Web.Plugins.Authentication" %>
How i may say the same in MVC 3.0 razor view ?
More details and solution:
I did build pluggable MVC application where i am having one Main App and a lot of Plugins in it. All assemblies and views output from Plugins Apps located not in Bin directory of Main App, and in Razor case i was experienced some problems that views cant find model classes.
Finally i did come the solution for that problem. I did make output of all *.dll of Plugins Apps in to Bin Directory of "Main App".
You will not find the equivalent of the Assembly Directive in Razor.
The reason is somewhat convoluted, but it begins with the decision of the MVC team to use WebForms for the first two versions of ASP.NET MVC. WebForms are used for many more things than just views in MVC. What MVC does is simply to re-purpose the WebForms engine to render views.
On the other hand, Razor is a plain view engine. Its objective is to provide a language to describe the rendering of HTML in an MVC website, nothing more.
Perhaps if you detail what you want to achieve we could help you in more detail
Yet another.
web.config
system.web
compilation
assemblies
add assembly
MVC RazorView class(inherit BuildManagerCompliledView) is using BuildManagerWrapper.
If code base change ,implement IBuildManager.GetReferencedAssemblies method and custom WebPage Helper.
In that case all *.dll's should be located in the correct place - in Bin directory of the main project "Main App".