Add Custom Webparts to Custom ASPX Page in SharePoint 2010 - sharepoint-2010

I am creating a custom aspx page to deploy to my SharePoint 2010 site.
Is it possible to have regions in my custom aspx page to allocate webparts to?
I am planning on creating some custom webparts and being able to move them around the page if needed would be a benefit for my aspx page.
Thanks.

Yes, use the standard WebPartZones with the sharepoint master pages (so you can add/configure the webparts)
<%# Page language="C#" MasterPageFile="~masterurl/default.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Import Namespace="Microsoft.SharePoint" %>
<%# Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<WebPartPages:WebPartZone runat="server" FrameType="None" ID="Main" Title="loc:Main"></WebPartPages:WebPartZone>
</asp:Content>
If you dont have the sharepoint master page, or any master page, you could still have the zones, but it is going to be hard work setting up the webpart editing tools.

Related

Umbraco not authenticating against Active Directory

I'm creating an internet site for the follow configuration:
- public website
- users need to authenticate agains active directory
- roles are servered by an 3th party ERP system, also using AD for authentication
What I have done
So I tried to follow this guide (https://our.umbraco.org/wiki/how-tos/membership-providers/active-directory-membership-provider) for the authentication, and wrote a custsom role provider for the ERP roles. I used the built in template for the login form.
The role part works just fine. The authentication does not.
The problem
It seems that Umbraco is still using the UmbracoMembershipProvider. When I create a member in umbraco I can login with the umbraco credentials. When I try any AD accounts it won't authenticate.
I tried to
Change the LDAP connectionstring to use a non existing OU or CN. It gives me errors, so connection to AD is made somewhere in the proces.
I also tried RB.ActiveDirectoryProviders. Same result.
I don't get any exception thrown, just "Invalid username or password". The logs say:
2015-08-19 08:45:20,764 [126] INFO Umbraco.Core.Security.UmbracoMembershipProviderBase - [P6460/T133/D8] Login attempt failed for username nico from IP address ::1, the user does not exist
My best guess I made some configuration error.
So how do I use Active Directory as only MembershipProvider?
Any help is welcome.
My setup:
local box with iis/umbraco/VS2012 running a virtual PC with the AD. I run Umbraco 7.2.8 in Visual Studio/IISExpress. I used the Nuget package of Umbraco.
web.config
<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP://192.168.2.50/dc=XXX,dc=YYY" />
</connectionStrings>
<membership defaultProvider="ADMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add name="UmbracoMembershipProvider" type="Umbraco.Web.Security.Providers.MembersMembershipProvider, Umbraco" minRequiredNonalphanumericCharacters="0" minRequiredPasswordLength="4" useLegacyEncoding="true" enablePasswordRetrieval="false" enablePasswordReset="true"
requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Member" passwordFormat="Hashed" />
<add name="UsersMembershipProvider" type="Umbraco.Web.Security.Providers.UsersMembershipProvider, Umbraco" minRequiredNonalphanumericCharacters="0" minRequiredPasswordLength="4" useLegacyEncoding="true" enablePasswordRetrieval="false" enablePasswordReset="true"
requiresQuestionAndAnswer="false" passwordFormat="Hashed" />
<add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ADConnectionString" connectionUsername="[USER]" connectionPassword="[PASSWORD]"
attributeMapUsername="sAMAccountName" />
</providers>
</membership>
#using (Html.BeginUmbracoForm<UmbLoginController>("HandleLogin"))
{
<fieldset>
<legend>Login</legend>
#Html.ValidationSummary("loginModel", true)
#Html.LabelFor(m => loginModel.Username)
#Html.TextBoxFor(m => loginModel.Username)
#Html.ValidationMessageFor(m => loginModel.Username)
<br />
#Html.LabelFor(m => loginModel.Password)
#Html.PasswordFor(m => loginModel.Password)
#Html.ValidationMessageFor(m => loginModel.Password)
<br />
<button>Login</button>
</fieldset>
}
After hours of searching I finally resolved this. It seems that the UmbLoginController always uses the UmbracoMembershipProvider. This is in my opinion not transparent.
Anyhow, I created a new surface controller like mentioned here and everything works fine now.

ADD PortletResource permission for specific users to VIEW custom portlet PROGRAMATICALLY

I want my custom portlet to be view-able by specific users but they're ALL MEMBERS OF SAME GROUP/SITE.
i.e...
User 1: my custom Portlet is not view-able
Admin: my custom portlet is view-able
User 2: my custom portlet is view-able
How to ADD Portlet-Resource permission for particular user to VIEW custom portlet PROGRAMATICALLY in my Jsp???
Here's my code..
<%#page import="com.liferay.portal.security.permission.ActionKeys"%>
<%#page import="com.liferay.portal.security.permission.PermissionChecker"%>
<%#page import="com.liferay.portal.model.Permission"%>
<%# taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%# page import="com.liferay.portal.theme.ThemeDisplay" %>
<%# page import="com.liferay.portal.kernel.util.WebKeys" %>
<%# taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%#page import="com.liferay.portal.service.RoleLocalServiceUtil"%>
<%#page import="com.liferay.portal.service.UserLocalServiceUtil"%>
<portlet:defineObjects />
<theme:defineObjects/>
<% ThemeDisplay themeDisplay = ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
long companyId = themeDisplay.getCompanyId();
long roleId = RoleLocalServiceUtil.getRole(companyId, "Administrator").getRoleId();
long userId = themeDisplay.getUserId();
UserLocalServiceUtil.hasRoleUser(roleId, userId);
if(permissionChecker.hasPermission(roleId, "com.test.sokbu", 10162, ActionKeys.VIEW)){System.out.println("Ok!");}%>
Thank you in advance!
Best Regards,
Cjohn
I just followed this link http://agile-reflections.opnworks.com/2011/07/experimenting-with-liferay-permissions.html and viola! it's now working! =) Thanks to Sir Laurent Gauthier
THIS IS MY SAMPLE.
STEP 1
Create a resource-actions folder inside docroot/WEB-INF/src
Create perm.xml
<?xml version='1.0' encoding='UTF-8'?>
<resource-action-mapping>
<portlet-resource>
<portlet-name>permissions</portlet-name>
<permissions>
<supports>
<action-key>VIEW</action-key>
<!-- <action-key>DELETE</action-key> -->
</supports>
<site-member-defaults>
<!-- <action-key>VIEW</action-key> -->
<!-- <action-key>DELETE</action-key> -->
</site-member-defaults>
<guest-defaults>
<!-- <action-key>VIEW</action-key> -->
</guest-defaults>
<guest-unsupported>
<action-key>VIEW</action-key>
</guest-unsupported>
</permissions>
</portlet-resource>
</resource-action-mapping>
Create default.xml
<?xml version="1.0"?>
<resource-action-mapping>
<resource file="resource-actions/perm.xml" />
</resource-action-mapping>
STEP 2
- Create a file named portlet.properties inside docroot/WEB-INF/src
- Insert this.. resource.actions.configs=resource-actions/default.xml
STEP 3
- Insert <add-default-resource>true</add-default-resource> after </css-class-wrapper> tag in liferay-portlet.xml.
STEP 4
Here I followed what's on the blog of Sir Laurent..
Open a browser on your Liferay instance as Liferay administrator
Create a new role named "Example Role"
Create a new user named "Example User" and set the user's password
Assign the "Example Role" to the newly created user
Open a different browser on your Liferay instance so as to have a different session, log in as "Example User" and navigate to the page containing this portlet
Pls Note
Whenever I have changes in perm.xml, I restart my server for changes to take effect.

ASP.NET MVC 4 Razor view not recognizing Dropdownlistfor HTML Helper

I am trying to add a dropdownlist to a strongly typed razor view. ASP.Net MVC 4.0, Razor View engine version 2.0.0.0
#using System;
#model SampleApp.Models.ServiceRequestModel
#{
ViewBag.Title = "ServiceRequest";
}
#Html.DropDownListFor(m=>m.CategoryID, Model.Categories)
and the Model is as below:
public class ServiceRequestModel
{
public int ID { get; set; }
public int CategoryID { get; set; }
public SelectList Category { get; set; }
}
it is always showing an error in intellisense in CSHTML file as:
System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'DropDownListFor' and no extension method 'DropDownListFor' accepting a first argument of type 'System.Web.WebPages.Html.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)
and also it is giving errors for :
Error 3 The name 'model' does not exist in the current context
I have checked the web.config in View folder:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
The below line of config code had to be changed to 4.0.0.0
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, **Version=3.0.0.0**, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
changed to
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, **Version=4.0.0.0**, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
I spent over a day on this error and it ended up being a data type clash with the VM data source for the dropdownlist (ie it wasn't a list of type IEnumerable). For some reason VS2012 thought the error was with the namespace even though it appeared in Intellipath.
I had this exact issue (only with html.displayFor).
I'm not sure how it started but i solved it by replacing the following:
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
with
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
</appSettings>
in the View folder's Web.config file.
Found my solution here

Sharepoint - Custom Integer Column - Remove thousand separator in EditForm

I created a new column definition in Sharepoint 2010 of type integer and with Commas set to false.
A content type uses this column.
When I create a list based on the content type, the "View Item" form will display the field correctly: 2010.
The EditForm however will display it as 2,010: with a comma although commas is set to false.
This is a new integer field (not a number field converted to integer)
Any ideas how to display 2,010 as 2010 in the EditForm?
<Field
ID="{FF3B3FA8-AF33-4691-AD7E-1463DC024B99}"
Name="studyYear"
StaticName="studyYear"
DisplayName="Study year"
Title="Year"
Description="Study year"
Required="FALSE"
Group="Custom Columns"
Type="Integer"
Commas="FALSE"
Min="1900"
Max="2300"
MaxLength="4">
</Field>
I wanted to group list items by Year based the Created field, but needed to covert number to text to avoid 1000 separator (,)
So I created a calculated field with formula of =LEFT(YEAR(Created),1)&RIGHT(YEAR(Created),3)
I have a custom field definition that I created in SharePoint 2010.
I basically followed the pattern set forth in this MS walkthrough. - then I changed their custom 'Field' example which inherits from 'SPFieldText' to instead inherit from SPFieldNumber, and my FieldControl inherits from NumberField.
Also, here's my field definition XML:
<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
<FieldType>
<Field Name="TypeName">Wps</Field>
<Field Name="SQLType">int</Field>
<Field Name="InternalType">Integer</Field>
<Field Name="ParentType">Number</Field>
<Field Name="TypeDisplayName">Client WPS integer</Field>
<Field Name="TypeShortDescription">Client WPS number</Field>
<Field Name="UserCreatable">TRUE</Field>
<Field Name="ShowOnListCreate">TRUE</Field>
<Field Name="ShowOnSurveyCreate">TRUE</Field>
<Field Name="ShowOnDocumentLibraryCreate">TRUE</Field>
<Field Name="ShowOnColumnTemplateCreate">TRUE</Field>
<Field Name="FieldTypeClass">MyCompany.SharePoint.WpsField, $SharePoint.Project.AssemblyFullName$</Field>
</FieldType>
</FieldTypes>
Like Karel, I had defined everything well enough that all commas were squashed.. except in the edit form.
I ended up adding some javascript to the custom .ascx that is part of my custom field definition.
<%# Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%# Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%# Import Namespace="Microsoft.SharePoint" %>
<%# Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Control Language="VB" %>
<SharePoint:RenderingTemplate ID="WpsFieldControl" runat="server">
<Template>
<span id="commaField">
<asp:TextBox ID="TextField" runat="server" Width="120px" />
</span>
<script type="text/javascript">// <![CDATA[
var numFld = document.getElementById("commaField").childNodes[0];
numFld.value = numFld.value.replace(",", "");
// ]]>
</script>
</Template>
</SharePoint:RenderingTemplate>
Note that I wrapped my ASP.NET TextBox in a simple SPAN with an ID that I could easily locate the field using getElementById in my JS. This was acceptable in my scenario, because the nature of our business would only ever require a single instance of my field type on a given SharePoint list record.
This seemed to solve everything for me! Maybe not the prettiest, but, I like that I don't have to clog up my list definitions with calculated columns.

Apache Struts: Cannot retrieve ActionForward

I am trying to learn the Apache Struts framework and I have written a small application that does class enrollments but whenever I try and load up my application it just spits out the following exception:
javax.servlet.ServletException:
org.apache.jasper.JasperException:
javax.servlet.ServletException:
javax.servlet.jsp.JspException: Cannot create rewrite URL:
java.net.MalformedURLException: Cannot retrieve ActionForward named adminLogin
My index.jsp page looks like:
<%# taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<logic:redirect forward="showLogin"/>
The relevant parts of my struts-config.xml:
<global-forwards>
<forward name="showLogin" path="/showLogin.do" />
</global-forwards>
<action-mappings>
<action path="/showLogin" forward="/pages/choose.jsp" />
<action path="/adminLogin" forward="/pages/adminLogin.jsp" />
</action-mappings>
And finally the choose.jsp file:
<%# page import="javax.sql.*"%>
<%# taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%# taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<h1>Who are you?</h1>
<ul>
<li><html:link forward="adminLogin">Administrator</html:link></li>
<li><html:link forward="instructorLogin">Instructor</html:link></li>
<li><html:link forward="studentLogin">Student</html:link></li>
</ul>
I don't do Struts, so don't pin me on it, but the error seems to indicate that it is expecting a <forward name="adminLogin" /> somewhere in the config. You might want to have the same for the other two forwards.