In a Siteocre project I want to compile all cshtml files using the MvcBuildViews setting. Unfortunately this also compiles any ascx and aspx files. I get an error like :
32>/temp/Sitecore/admin/Wizard/InstallationLog.ascx(1): error
ASPPARSE: The base class includes the field 'logPanel', but its type
(System.Web.UI.HtmlControls.HtmlGenericControl) is not compatible with
the type of control (System.Web.UI.HtmlControls.HtmlIframe).
Is there a way to restrict the view compilation to cshtml only?
I will transform my comment into an answer.
Your approach to have Sitecore inside your Visual Studio folder is not correct.
You need to separate your Visual Studio and website folder where IIS is mapping your site.
On next link is explained very well how to create a Visual Studio Project for Sitecore MVC .
http://sitecore-community.github.io/docs/sitecore-mvc/creating-project/
Related
I have now build a webpage for some API stuff- I now want to use the index.cshtml file (which is build into the structure) - but when I open the index.cshtml file or the Layout.cshtml or the Error.cshtml file in the Visual Studio - I get the exception message as:
CS1980 C# Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you missing a reference?
For some time ago, the Azure was installed in my project by a mistake - but I uninstalled it (maybe that was the reason).
I have deleted the View folder (where the index file was included) and added the it again, like on this video.
I'm writing a small website using ASP.NET, writing the C# into the .aspx file directly without using code-behind or compiling a DLL. I do this mainly to allow small edits with just a text editor without having to keep going back to Visual Studio.
This is working great, except I want to write a class for some code that will be used by multiple .aspx pages. Is there a way I can add a .cs file in the same way I have C# code in .aspx files?
Good question.
I assume you have a "Web Site" in Visual Studio. If not then perhaps you should invest the time to create a new Web Site and migrate the pages into it. Then publish it and that will make things easier. The problem you describe here will be solved plus other things. If you modify the web site outside of Visual Studio however then that would probably be a problem too. I am a beginner but you probably can open the site live for editing directly. I am not sure.
I was curious about how to do what you are asking so I explored.
Anyway, assuming you already have a Web Site in Visual Studio, use "WebSite" | "Add New Item" to add a class. VS will ask you if you want to create an APP_CODE, say yes. The cs file won't have a namespace, the class will be in the global namespace.
When I got that far I was able to use VS to test a page using the class. When I copied the source, IIS said it could not find the class. So be sure that the APP_CODE directory is in the root of the web site. That probably is not enough so we will continue.
I published the web site. The published web site worked, it found the class. I could not figure out what the difference is between the published site and what I copied over. So I studied the output of the publish and I see it is creating virtual directories and adding ACLs.
I think this is the trick. First be sure the APP_CODE directory is in the root of the web site. Then go into the IIS Manager and find the web site. Right-click and select "Convert to application". When I did that the files that I just copied worked.
If you publish the site using Visual Studio then it will do that for you. You only need to do it once.
I tried a few other things so there might be something else I did that is necessary but I do not think so.
Add something like the following at the top of your .aspx file -
<%# Import namespace = "mydll" %>
This will ensure that the class is accessible in the mark-up, assuming the methods and properties etc are setup to be so.
Any changes to the dll will still require you to edit and build in VS however.
I am following the instructions for using .less to minify the css.
I have included the dll and made the Web.config changes.
However, when I refer to it in index.cshtml as Less.Parse, the Less namespace is not available and I get the exception "The name Less does not exist in the current context."
What am I missing?
I have solved it. It was just missing the parent namespace. Now conversion works like a charm.
dotless.Core.Less.Parse(css)
If you are using Visual Studio, Web Essentials has support for less.
http://vswebessentials.com/features/less
I often use it for :
.less to .css preview
View output from a .less compile
Extract variables/mixins
After build if you go to Output and select Web Essentials from the 'Show output from:' dropdown, you will see a date, time and the list of .less files that have compiled.
when I used to create ASP.NET website there was only one code behind file as for example Default.aspx.cs. Meanwhile I created ASP.NET web application, this time visual studio generated an additional code behind file as Default.aspx.designer.cs My question why do I need it ? I inherited a class other than the Page class, so I removed "inherits="MySite.Default". But I've got an error mentioning identifier expected in the Default.aspx.designer.cs file. Please help me in this regard too.
the designer files are auto-generated by visual studio and act like scaffolding for the code you write within the aspx and aspx.cs files. Because these are auto-generated you never need to or should touch these files.
I would advise you put the code back where it was, inherit from your desired other class as you wish and let visual studio worry about the designer file.
Simply make the changes your need to those the aspx and aspx.cs files and forget about the designer files.
Find more info here: aspx.designer.cs how does it work?
I recently updated my VS2010 website project from .NET 3.5 to 4.0. Everything was working fine in the website project. Today I decided to migrate the website to a web application project as I have learned this is the best way to work in .NET. I split out all my class files into a separate class library and copied all my other content into my new project. Then I updated all the references and web.config.
When I build the class library, everything works great.
The problem is happening when I try to build/debug the web application project. It is acting like all the controls are missing and it is also throwing a bunch of compile errors about the public properties I have in my master pages.
Control errors:
"The name 'INSERT CONTROL NAME HERE' does not exist in the current context"
Master page errors:
'System.Web.UI.MasterPage' does not contain a definition....
It is giving these errors for every single control and master page property in my entire solution.
I notice when I add a new web.form to this project, it also adds a filename.aspx.designer.cs file in addition to the .aspx and .aspx.cs file. My existing files do not have these extra files since they were created in a different .NET version.
Anyone have an idea on how to overcome these issues?
UPDATE: It seems I was missing the step where I need to right click on the new application folder and select "Convert to web application". I just did that and it seems to be a little bit better...
Now it is choking on Literals that are inside single quotes:
<div class='<asp:Literal ID="CssClassLiteral" runat="server"></asp:Literal>'>
It doesn't see this literal when it does the conversion... Is the above valid code or should I implement that functionality another way?
Yes - one of the main differences between the website project and a web application project in Visual Studio is that the web application project defines a designer.cs file for every page/user control.
So, let's say you have a page in a website with a codebehind:
Default.aspx
Default.aspx.cs
In a web application, the designer is now required:
Default.aspx
Default.aspx.designer.cs
Default.aspx.cs
The designer file is auto-generated, but you may need to "touch" each page to generate.