I would like to create an anonymous page in SharePoint Intranet Site. All rest of the site is using windows claims authentication but I want to create single page which should be anonymous.
I believe there is a way to create a page in IIS under layouts directory and it can be accessible anonymously but I am not able to make it work. Anybody has any idea?
Editing it with the code I have so far
<%# Import Namespace="Microsoft.SharePoint" %>
<%# Page Language="C#" AutoEventWireup="true" Inherits="Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase" DynamicMasterPageFile="~/_layouts/15/ErrorV15.master" %>
<HTML>
<script runat="server" language="C#">
protected override bool AllowAnonymousAccess
{ get{ return true; } }
protected override bool AllowNullWeb
{ get { return true; } }
protected void Page_Load(object sender, EventArgs e)
{
}
</script>
<body>
<form id="MyForm" runat="server">
Application page
</form>
</body>
</HTML>
Thanks!
In SharePoint, you shouldn't change any files manually.
You should start with a SharePoint form solution project in your Visual Studio and it will produce a WSP file. By installing it, the SharePoint platform will place it in the correct location (psst, the 15 hive).
In that project, you'll need to add an application page and it needs to inherit from UnsecuredLayoutsPageBase and override the AllowAnonymousAccess property, returning true.
Related
I have an old application uses wicket 1.4 and want to integrate the liferay reCAPTCHA ( liferay 7.4).
Is there any guide for that?
Or anyone might help ?
It worked for MVC portlet like the following but still cannot achieve same in wicket :
Use CAPTCHA or reCAPTCHA with custom portlet in Liferay MVC Portlet:
CAPTCHA is a “Completely Automated Public Turing test to tell Computers and Humans Apart”. It is used in the computer world to determine whether an end-user is human or non-human. Liferay provides the necessary API as well as tag library to implement CAPTCHA in your custom portlet. Also, you can integrate Google reCAPTCHA in your custom portlet.
Prerequisites
Java
Liferay portal 7/7.x
Use CAPTCHA in custom portlet
Assuming you’ve already created a Liferay-workspace project
Follow below steps to implement CAPTCHA in your custom portlet
Create MVC Portlet
Go to liferay workspace project → modules → new
Select other → Liferay → Liferay Module Project and Click on Next
Enter project name
Select “Project Template Name” as “mvc-portlet” and Click on “Next”
Enter Package name and Click on “Finish”
The necessary file structure for MVC module will get created as below :
2) Now we add below code in view.jsp
<%# include file="/init.jsp" %>
<%# taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>
<%# taglib uri="http://liferay.com/tld/captcha" prefix="liferay-captcha" %>
<%# page import="com.liferay.portal.kernel.captcha.CaptchaTextException"%>
<portlet:actionURL name="basicFormDataWithCaptcha" var="basicFormDataWithCaptchaAActionURL" />
<portlet:resourceURL id="captcha" var="captchaResourceURL"/>
<liferay-ui:error exception="<%= CaptchaTextException.class %>" message="captcha-verification-failed" />
<aui:form method="post" name="basicForm" action="<%= basicFormDataWithCaptchaAActionURL %>">
<aui:input name="firstName" >
<aui:validator name="alpha"/>
</aui:input>
<aui:input name="lastName" >
<aui:validator name="alpha"/>
</aui:input>
<liferay-captcha:captcha url="<%= captchaResourceURL %>"/>
<aui:button type="submit" value="Submit"></aui:button>
</aui:form>
3) Create Action method in CustomCaptchaPortlet
package ...;
import ...;
#Component(
...
)
public class CustomCaptchaPortlet extends MVCPortlet {
private Log log = LogFactoryUtil.getLog(this.getClass().getName());
#ProcessAction(name = "basicFormDataWithCaptcha")
public void basicFormDataWithCaptcha(ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
String firstName = ParamUtil.getString(actionRequest,"firstName");
String lastName=ParamUtil.getString(actionRequest,"lastName");
log.info("First Name : " + firstName);
log.info("Last Name : " + lastName);
try{
CaptchaUtil.check(actionRequest);
log.info("CAPTCHA verification successful.");
}catch(Exception exception) {
if(exception instanceof CaptchaTextException) {
SessionErrors.add(actionRequest, exception.getClass(), exception);
log.error("CAPTCHA verification failed.");
}
}
}
#Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
throws IOException, PortletException {
try {
CaptchaUtil.serveImage(resourceRequest, resourceResponse);
}catch(Exception exception) {
log.error(exception.getMessage(), exception);
}
}
protected boolean isCheckMethodOnProcessAction() {
return _CHECK_METHOD_ON_PROCESS_ACTION;
}
private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;}
Output with CAPTCHA
Use Google reCAPTCHA in custom portlet
To integrate Google reCAPTCHA in Liferay please follow below steps
1) Get Site key & Secret key from Google reCAPTCHA
Go to www.google.com/recaptcha in your web browser
Click on “Admin console” button (Located at top-right corner)
Fill up your details in the form and then click on “Submit”
4- You will get “Site key & Secret key” as below image. This you will require while configuring Google reCAPTCHA with Liferay
2) Enable Google reCAPTCHA in your Liferay
Login as admin user
Navigate to Control Panel → System Setting → SECURITY → Security Tools → CAPTCHA
Go to CAPTCHA Engine and change it to reCAPTCHA
Enter “reCAPTCHA public key” and “reCAPTCHA private key”
You need to enter the values you got from Google reCAPTCHA site in previse step , “reCAPTCHA public key” field, and “secret key” in “reCAPTCHA private key” field
Click on ‘Save’
To test Google reCAPTCHA is properly configured or not. Logout from Liferay and go to Create Account page. You can see a default Liferay CAPTCHA is replaced with the new Google reCAPTCHA
3) Use Google reCAPTCHA in your Custom Portlet
Once you configure reCAPTCHA from control panel below, code will render google reCAPTCHA
<liferay-captcha:captcha url="<%= captchaResourceURL %>"/>
If we configure reCAPTCHA from Liferay control panel, Output of above ‘custom-captcha-portlet’ will look like below
As you see it works for MVC portlet but I have some code written in apache wicket which I did not find a way to achieve same and wondering if there is a way to integrate Liferay reCAPTCHA with wicket somehow ?
I am building a web application using the ASP.NET Core 3.1 MVC and Razor pages.
I am new to Razor pages.
I created a basic application using above. I want to load the Login page on start of the application but
the Index.cshtml page seems to be the start page.
To redirect from the Index.cshtml page (start page) to my Login.cshtml page, I did following in the Index.cshtml PageModel. But it is not working.
EDITED:
Index.cshtml:
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about building Web apps with ASP.NET Core.</p>
<form method="get" asp-page="Index" hidden name="myForm">
<input type="submit" name="submit" value="Redirect 1" asp-page-handler="Redirect1" hidden />
</form>
</div>
Index.cshtml.cs:
public class IndexModel : PageModel
{
public IndexModel()
{
OnPostRedirect1();
}
public void OnGet() {}
public IActionResult OnPostRedirect1()
{
return RedirectToPage("Login");
}
}
How to automatically redirect to Login page from Index page?
You have some options. If you don't want unauthorised users to visit the Index page, apply the [Authorize] attribute to the PageModel class:
[Authorize]
public class IndexModel : PageModel
{
...
}
Then, if your login page is not located at /account/login, configure the login page in Startup:
services.ConfigureApplicationCookie(options =>
{
options.LoginPath = "/YourLoginPage";
});
The framework will automatically redirect unauthenticated users to the login page. This is what most people are likely to do. Or, if you don't want Index at all, remove it and set the login page as the home page by changing its route template:
#page "/"
This will override the conventional route for the page, based on its file path: https://www.learnrazorpages.com/razor-pages/routing#override-routes
I have two public pages, each having a portlet.
For the first portlet, on click of a button, I want to open up the other portlet.
Is there any simple way to do this in liferay 6.2?
So far, I tried -
Currently from the group/game/portal page ->
<script>
function manageGame() {
response.sendRedirect('group/games/manage');
}
</script>
<button onClick="manageGame()">Manage</button>
Either you can create URL in controller and pass it to JSP as below
PortletURL liferayURL = PortletURLFactoryUtil.create(renderRequest,<<portlet-name>>, <<Plid>>,PortletRequest.RENDER_PHASE);
renderRequest.setAttribute("anotherPortletUrl", liferayURL);
JSP
click here
OR
You can create Liferay Portlet Render URL in JSP as below
<%#page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<%# taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<liferay-portlet:renderURL plid="10180" portletName="portlet-name" var="openForm" windowState="<%=LiferayWindowState.POP_UP.toString()%>"></liferay-portlet:renderURL>
With above two methods you can create a url on click of which portlet on other page will be opened.
If you portlet is instanciable add instance with portletname
I am looking to create a page with a single form on it that does the following:
Contact a webservice with input from the form.
Perform an action (programmed using C#) depending on the result of the webservice call.
Since I am not interacting with any lists or similar on the SharePoint site, I was thinking a WebPart would be the simplest way to add the form and catch the submit-event, but I am not sure if this is the best practice or an easier/better way exists.
I also need to restrict access to the form to a specific usergroup.
Thanks in advance!
A new SharePoint Web Part is probably the most common way to provide this solution in SharePoint and fits your requirements well. Though your solution doesn't call for it, you do have access to the lists from custom web part code.
If you are using SharePoint 2007, Visual Studio Extensions provide the Microsoft supported way to create one easily. It's much easier with Visual Studio 2010 and SharePoint 2010.
Some other options would be an InfoPath Form with custom code or a custom application page with code behind. The benefit of the web part is that it works with all versions of SharePoint and can be added to any web part page on the site and customized by users. Also, the application page may not pick up the master page if you are on SharePoint 2007.
Use WebDAV to upload an ASPX page to a site in SharePoint. Then upload your assembly to each SharePoint server, the bin folder of your application is preferred, or add it to the GAC.
Your ASPX page might look like this:
<%# Page Language="C#" masterpagefile="~masterurl/custom.master" inherits="MyAssembly, MyClass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c48b11b32c9eb4a7" %>
<asp:Content runat="server" ContentPlaceholderID="PlaceHolderPageTitle">My Title</asp:Content>
<asp:Content runat="server" ContentPlaceholderID="PlaceHolderPageTitleInTitleArea">My Page</asp:Content>
<asp:Content runat="server" ContentPlaceholderID="PlaceHolderMain">
<asp:Button runat="server" ID="ButtonClickMe" Text="Click Me!" />
</asp:Content>
Then your assembly might look something like this:
public class MyClass : Microsoft.SharePoint.WebPartPages.WebPartPage
{
protected global::System.Web.UI.WebControls.Button ButtonClickMe;
protected override void OnLoad(EventArgs e)
{
base.OnLoad( e );
ButtonClickMe.Click += new EventHandler( ButtonClickMe_Click );
}
void ButtonClickMe_Click(object sender, EventArgs e)
{
if (!Page.IsValid)
return;
// Do stuff here
}
}
You won't be able to edit the permissions of the ASPX page directly, but you can manipulate the permissions of the site it is in (thus, restrict the site to only the usergroup which you want to access the form).
I am developing a publishing portal in SharePoint. The page layouts, master pages are designed using Visual Studio and I deploy the page layouts into the content database using wspbuilder.
I have a requirement wherein I have to access the controls of the page layout in code behind and assign or get values to/from the controls. But, the VS intellisense never shows the controls used in my page layout. What should I do in order to access the controls using code behind?
Is there any workaround for this?
Regards,
Raghuraman.V
You have to make the web controls on the user control public.
Here's a quick example showing how to change a user control's textbox from the parent page:
WebUserControl1.ascx:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication1.WebUserControl1" %>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
WebUserControl1.ascx.cs:
using System;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebUserControl1 : System.Web.UI.UserControl
{
public TextBox UserControlTextBox1
{
get { return TextBox1; }
set { TextBox1 = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
WebForm1.aspx:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<%# Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
</div>
</form>
</body>
</html>
WebForm1.aspx.cs:
using System;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
WebUserControl11.UserControlTextBox1.Text = "Your text here...";
}
}
}
I guess that you have the page layouts and the code-behind in two different projects or at least in two different locations. You can also use 'real' code-behind pages in SharePoint that are side-by-side with the ASPX file so that you do not have to re-declare the controls at all.
To do so you can create the Visual Studio project for the WSP package as an
“ASP.NET Web Application”, create ASPX pages with code-behind files side-by-side and use WSP
Builder to remove the C# files from the package (the code is still compiled into the assembly and deploy with it). The trick works because WSP Builder can be
configured with a local configuration file within the Visual Studio project to remove certain file
types.
Here the local WSPBuilder.exe.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Excludefiletypes" value="cs" />
</appSettings>
</configuration>