MvcSiteMapProvider is using ascx - asp.net

I have donwloaded the Nuget package, MvcSiteMapProvider.
In one project it only downloaded the razor views. In my other, I have both the Razor and ascx files. Also in that project it is default to using the ascx. I want it to use the razor pages instead. Does anyone know how to switch this.

When the NuGet package detects no files with a .aspx extension in your project or detects any files with a .cshtml or a .vbhtml extension, it will install the .cshtml templates. Unfortunately, there is no reasonable default when both .aspx and .cshtml extensions are detected or no files with the above extensions are detected, so this is a "best guess".
To install the Razor templates, you just need to delete the .ascx templates and copy the .cshtml templates from here.

Related

Are the cshtml files just copied when published?

Is it OK let the designers to download the cshtml files (MVC 4) from a published site and modify the files for layout/styling? (And later the developers' cshtml files can be replaced by the ones from designers)
If I remember correctly, the old version of Asp.Net webform may change the .aspx files after published. Will .cshtml files be untouched after published.
cshtml files means C Sharp HyperText Markup Language, e.i its html with C Sharp Code (Razor Syntax).
Offcourse your designers can download the cshtml file(mind it you cannot download cshtml files from a published website) edit it and reupload it. but make sure they dont tinker with the razor syntax.
Yes cshtml files can be modified to change the layout/styling on a published site.

Asp.net mvc3 localization - linking resource with view?

I use the localization paradigm of one resx file per view in all my projects. I have two identical folder structures for Resources and Views and I link the resource and the view like so:
#using Res = [Namespace].Resources.[Controller].[View]
<p>#Res.[ResourceKey]</p>
Is it possible to get asp.net to use/link the resource file without the using statements and defining a Custom Tool Namespace for all my Resx files? (Yes, I am that lazy.)
Open your web.config in your Views folder.
Add the namespace for your resources.
Restart VS as it doesn't pick up the namespace so it's not showing intellisense.
Call your resources from any view without adding using statements inside your *.cshtml files.

How asp.net application works?

I am quite new to .NET development and I am just wondering how does it work?
My undermentioned points are:
While developing ASP.NET application, under the project we have files like:
pagename.aspx
pagename.aspx.cs
pagename.asp.desiger.cs
After adding certain functionality to pagename.aspx page, assuming I have the development required web application (this is not my concern, what is developed)
Now I'm going to deploy this application, I use web deployment MSI which creates the required files in the one folder called folderdelopyed.
This folder contains the files required to support this application but interesting does not contain pagename.aspx.cs and pagename.aspx.designer.cs files.
My question is if folderdelopyed does not contain .cs file, then how does it work to run the segment of code which I have written in this file called PageName.aspx.cs?
The code in your cs files gets compiled into a dll.
For Web Application projects this is one dll
For Web Site projects, this is a dll per page.
All of the code is now in the dll's in the bin folder of the website.
You can use a tool like ILSpy (http://wiki.sharpdevelop.net/ILSpy.ashx) to look inside the dll's and see your code.
In the old days, for classic ASP, the script used to be embedded in your page - a mix of code and HTML, and was interpreted at runtime.
I like the new way more :-)
ASP.NET code is compiled into Dynamic-link library files, also known as DLL files.
The code you write in your code behind, which is the files with .cs extension, is compiled and put into whole new file, with .dll extension - and that file is copied to the server, to the BIN folder of your site.
Depending on what project type you choose, it's possible to have several DLL files for the web application, changing in every build - see dash's answer for more details.
On every .aspx page you have referece to what DLL file to use, as the very first line. For example:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="pagename.aspx.cs" Inherits="MyNameSpace.pagename" %>
In this example, the Inherits part determines what DLL to use. How? By the namespace, which is also the name of the DLL file.
When the above .aspx is requested by a browser, the .NET engine will go to the BIN folder, look for MyNameSpace.dll and in there look for class called pagename that inherits from the base Page class - all the rest is typical life cycle of ASP.NET page.
let me to say you something more Amazing.
you can hide your aspx file too.and put their content in to dll as same as your cs file put in dll.
you can make k aspx that just contain an address to the ddl file and no html body :D
that was greate!!! not only you can hide your cs file, you can hide you aspx file too :D

How to remove namespace from Inherits Attribute without a Parser Error, Could not load type

I've seen lots of posts about the Inherits Attribute, and the Parser Error "Could not load type"
I can get this working by putting "RootNamespace.PageName" for a specific page, where RootNamespace matches the Root namespace in my project properites.
But I would rather not put the namespace in there. i.e. I would rather put "PageName" than "Namespace.PageName".
I have a library project with a few DLLs and 10 or so .aspx and .ascx files.
To get an update of my library project, other projects in my company copy the DLLs in and then copy the .aspx and .ascx files into a specific folder in their project.
Only problem is every time they copy they have to change the Namespace of the inherits attribute to match the root namesapce in their project.
If they don't do this, they get no compiler errors but just get a Parser error when they hit the libary .aspx and .ascx files.
This is very annoying, it seems very ridiculous that so many pages will not work if the project root namespace changes.
Does anybody have any ideas on how I can make library pages and user controls for nuse withing other peoples projects?
Thanks,
Mike G
Ah ha! A colleague stumbled upon a way around this by accident...
OK I have a single shared "Library" project and many "normal" projects that make use of shared stuff from the Library...
1- Create a "Library" WebApplication that outputs a DLL, and put your web library code and also .ascxs and .aspx pages into the WebApplication project. 2- Reference the "Library" DLL in your "Normal" projects 3- Copy just the shared .aspx and .ascx files from "library" into the "normal" projects, but ... (important bit!) ... without the code behind
In our example we don't actually include the copied .ascx and .aspx files in the project (e.g. They're not referenced in the .vbproj file) and they don't get put in source control, they just get copied in from the library every time you build. We haven't experimented with what happens if you tell the project about the .aspx and .ascx files but they definitely load OK at run time.
So it does actually make sense no I think ab out it.
Basically the root namespace of the .aspx files is unachanged it's just refers to classes in the referenced library DLL so it all works.

Pre-compile specific directories in ASP.NET website project

I have an ASP.NET website project which has a mixture of updateable pages and pages that do not change.
Is it possible for me to pre-compile certain directories that contain pages/controls that will not be updated?
If so, how could I designate these directories as such?
Edit 2009.12.17
My project is structured like this:
/cms_pages ==> Updateable .aspx pages marked CompilationMode="never" and no code file.
/app_pages ==> .aspx pages with .aspx.cs code file.
/controls ==> .ascx controls with .ascx.cs code file.
I would like to "pre-compile" the app_pages and controls folders.
Is it possible to do?
Do you want to compile your ASPX pages with their codefiles or just compile some .cs files in your App_Code folder?
If you're just trying to version control some static functions or global objects you can compile a DLL to keep in your App_Code folder.
Not without a lot of headaches. How are you precompiling the pages now? They must be in a WAP for this to work... so anything you DON'T want precompiled just leave out of the project.
[Edit]
It's possible to manually call the asp.net compiler. But I don't recommend this. What you really need to do is split up your solution files into different projects... put the files you want pre-compiled into a Web Application Project or just a regular class library. Then in your Web Site add a project reference to this WAP.
Couldn't you just pre-compile all of the controls (and probably anything else) into an assembly then you can access them through myAssembly.myControl
Dim assembly As Reflection.Assembly = Reflection.Assembly.LoadFrom(Server.MapPath(Virtual path to assembly))
Dim myControlType As Type = assembly.GetType
Dim myControl As UserControl = LoadControl(myControlType, Nothing)
myPanel.Controls.Add(myControl )
Or
Dim myControl As Control = LoadControl(virtual path to control)
myPanel.Controls.Add(myControl )
Hope this helps..

Resources