MVC Project errors after adding .ascx control - asp.net-mvc-3

I've tried to add a .ascx user control to my EditorTemplates but doing so causes a hundred erros to pop up in my MVC 3 project. Every reference to "System." errors as "is not defined" and the compiler wants me to update them to "Global.System."
Can anyone tell me why adding the user control does this?
Thank you
UPDATE:
If i take out the code-behind files that are automatically created (and I don't think I need) then the problems seem to resolve. Very interesting...

User controls (stuff with runat="server") is not something that should be used in ASP.NET MVC application. They usually rely on Postbacks and ViewState which are notions that no longer exist in ASP.NET MVC. You could use an ascx partial/editor template and invoke it from a Razor view. So for example let's suppose that you have the following partial:
<%# Control
Language="C#"
Inherits="System.Web.Mvc.ViewUserControl<AppName.SomeViewModel>" %>
<%= Html.LabelFor(x => x.Foo) %>
<%= Html.TextBoxFor(x => x.Foo) %>
You could include it from a Razor view like this:
#Html.Partial("NameOfThePartial")

Related

Storefront login page redirects to path with null value instead of j_spring_security_check

We're doing a migration to Hybris 6.5, and while trying to login in the storefront, we are redirected to the path https://urreab2b.local:9002/urreab2bstorefront/urreab2b/es/USD/null instead of https://urreab2b.local:9002/urreab2bstorefront/urreab2b/es/USD/j_spring_security_check.
Due to this we get a error message [hybrisHTTP3] [PageNotFound] Request method 'POST' not supported, which makes sense since the login page in the storefront isn't mapped to null.
We checked in login.jsp and the value for loginActionUrl is set like this:
<%# page trimDirectiveWhitespaces="true" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="sptemplate" tagdir="/WEB-INF/tags/addons/secureportaladdon/desktop/sptemplate" %>
<%# taglib prefix="spuser" tagdir="/WEB-INF/tags/addons/secureportaladdon/desktop/spuser" %>
<%# taglib prefix="cms" uri="http://hybris.com/tld/cmstags" %>
<%# taglib prefix="common" tagdir="/WEB-INF/tags/desktop/common" %>
<sptemplate:page pageTitle="${pageTitle}">
<div id="globalMessages">
<common:globalMessages/>
</div>
<div class="span-24 last login_container">
<div class="span-9 last login-panel">
<c:url value="/j_spring_security_check" var="loginActionUrl"/>
<spuser:login actionNameKey="login.login" action="${loginActionUrl}"/>
</div>
</div>
</sptemplate:page>
But whenever we open the login page in the storefront the action value for the login form is set to null:
We don't understand why the value for the login action url is being overwritten nor who is responsible for this, we've even tried to modify directly the action inside login.tag to /j_spring_security_check but even modifying the tag directly doesn't stop the action from being set to null.
Another thing we tried was to modify the action value using Chrome Developer Console, and although we are redirected to the URL https://urreab2b.local:9002/urreab2bstorefront/urreab2b/es/USD/j_spring_security_check, and only then we are redirected correctly.
We printed on the JSP the value for action and the value it has is /urreab2bstorefront/urreab2b/es/USD/j_spring_security_check, so the value is arriving to the JSP correctly but the form is not taking it.
EDIT
I found a library called spring-security-taglibs-3.1.1.RELEASE in the lib folder, I removed it so it would take the latest version from the pom.xml, got JasperException due to a tag library using deprecated attribute ifAnyGranted so I replaced them with the recommended, that got rid of the exception but the form is still being assigned null on its action attribute.
Does anyone know what might be the cause? Is it something Spring related or something related to Hybris configuration or something else?
This is something related to spring security issue I guess. Could you please the security xml configuration
It seems you are using secureportaladdon but its not correctly installed to your storefront. Do verify first whether your addon is correctly installed or not. Addon should override the login functionality.
The html code what you are showing seems not to be coming from secureportaladdon rather from somewhere else.
Check addon installation step here
https://help.hybris.com/6.6.0/hcd/8adf7365866910149ceb975f778d809d.html
OR
https://help.hybris.com/6.6.0/hcd/8aeddd34866910149de2d448ff18df98.html

Check if image file exists using middleman

I have a website running on middleman. I'm trying to check if an image file exists. I followed the suggestion in "How to check for file existence", using File.file?, but it's not working. Here's the line of code:
<% if File.exists?("/source/images/doctor-#{doctor.slug}.jpg") %>
I tried a few different file paths:
/source/images/file
/images/file
../images/file
but none worked. In the browser, I can view the image file at "0.0.0.0:4567/images/file".
Any ideas?
Maybe it's easier to query those files via the Middleman Sitemap?
You gain access to it within templates via the sitemap object. One way of achieving your actual case could be:
<% if sitemap.find_resource_by_path("images/doctor-#{doctor.slug}.jpg") %>
<%# do what you want %>
<% end %>

Using webform master page in razor view

I have tried implementing this, but the extension methods are not working when I rewrite them in VB. I am trying to use a corporate master page in my MVC3 application. Right now I have my .Master and my .ascx page. I am confused on how to get it to show in my razor view.
my .ascx page:
<%# control Language="VB" Inherits="System.Web.Mvc.ViewUserControl" %>
<asp:Content ID="Content" ContentPlaceHolderID="ContentArea" runat="server">
<div>
Hello World
</div>
</asp:Content>
When I run it, it gives me this error: Content controls have to be top-level controls in a content page or a nested master page that references a master page.
I use my _ViewStart.vbhtmlto call on the .ascx page.
Trying to hack webforms objects to work with MVC3 is only going to cause you trouble down the road. Redo the file as an MVC3 layout using razor.
Edit: added
Layout File Tutorials:
Making layout pages
Understanding Layout Files
Layouts and Sections

Rails 3.x asset pipeline including coffeescript file in view

I have recently came across where I would like to simply just include a coffeescript file in a single Rails view, but when you use the javascript_include_tag it appends .js to the end of the name you pass in (for obvious reasons).
Has anyone come up with a solution to simply just include a coffeescript file on a page without this happening?
i did this to load only the relevant JS for each controller:
in application.html.erb where you see
<%= javascript_include_tag "application" %>
please add
<%= javascript_include_tag controller_path, :media => "all" %>
also remove the
#=import .
from application.js
this way only the myController.coffee.js is loaded from myController this way you can have a more granular control of the loaded js and you can use application.js for common code
it's not the best solution in terms of user download but if you don't care about a few more connections I find this easier to understand (same thing can be done with css)

Mixing Razor Views and Web Forms Master Pages

I'm attempting to do what Scott Hanselman describes below:
http://www.hanselman.com/blog/MixingRazorViewsAndWebFormsMasterPagesWithASPNETMVC3.aspx
I have a Web Form user control with code behind that is called from the Web Form and Razor Master Pages that is not working in the Razor layout:
<div id="navtop">
#{ Html.RenderPartial("~/Controls/MasterPageMenu.ascx"); }
</div>
The user control contains the following:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="MasterPageMenu.ascx.cs" Inherits="Controls.MasterPageMenu" %>
I get the error:
The view at '~/Controls/MasterPageMenu.ascx' must derive from ViewPage, ViewPage, ViewUserControl, or ViewUserControl.
What have I missed in getting this to work in the Razor view world?
This should work, just make sure that your partial derives from ViewUserControl:
<%# Control
Language="C#"
Inherits="System.Web.Mvc.ViewUserControl"
%>
Remember that using server side controls in ASP.NET MVC is not something that's recommended even with the WebForms view engine and not something that you should even be attempting to do. In ASP.NET MVC you have layouts (master pages if you use WebForms view engine), views and partials. That's all. User controls belong to classic WebForms, not to ASP.NET MVC.

Resources