SharePoint 2007 - /_layouts and how to create pages that run in site context

本文介绍了一种在SharePoint2007中创建和部署自定义页面的方法,使页面能在站点上下文中运行。这种方法避免了将所有服务器端代码包含在aspx页面中,而是使用独立的代码隐藏文件,提高了开发效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

Ages ago, in the time that SharePoint 2007 was still beta, I dived into how to create "in site context" pages that should be hosted in the /_layouts directory of SharePoint. My adventures from back then can be found in this blog post. I don't want to take the default Microsoft approach where all server-side code is included in the aspx pages themselves. Developing this way is way more difficult that using code-behind files. I found a solution by creating a Visual Studio 2005 web site in the /_layouts virtual directory of my SharePoint web site, which points to the physical folder C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/LAYOUTS. In this approach all code behind files are part of the solution, and are compiled and cached on page request. Although this approach works, I don't really like it. I prefer the Visual Studio 2003 approach where all code-behind is compiled into a single assembly that can be deployed. Another problem is the location of referenced assemblies. I had my referenced assemblies in the GAC, but I prefer to deploy to a bin folder so no IISRESET recycling of the SharePoint application pool is needed on recompilation.

What I really want to achieve is the following:

Create a web application project that can be deployed to the SharePoint /_layouts virtual directory, so my code is executed in the context of a site.

The solution happens to be really easy:

Create a web application project, either directly in the /_layouts folder or somewhere else and copy over all files needed to run your application.

The *.dll and *.pdb files produced as build output must be places in the bin folder of your SharePoint web site. In my test situation this is the folder C:/Inetpub/wwwroot/wss/VirtualDirectories/3a938f6a-15f2-49ae-be78-328ad78974f5/bin. You can find this folder in your Internet Information Server Manager as follows:

  • Right-click of the SharePoint web site
  • Select properties
  • Go to the Home Directory tab

The value in Local Path specifies the path to the virtual directory, and in this virtual directory you find a folder bin.

If you create your web application project within the /_layouts virtual directory, you can set the build output path directly to this bin folder.

Note that you can't use the Publish Web feature of the web application project, because you can't specify a separate path to deploy your assemblies to:

For my test I created the following project:

I added some really simple code to the Default.aspx and Default.aspx.cs files to prove that it works:

Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SergeLayoutsTest._Default" %>

<!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>Site title test</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Title of this site: <asp:Label ID="LabelTitle" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

 Default.aspx.cs:

using System;
using Microsoft.SharePoint;

namespace SergeLayoutsTest
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SPWeb web = SPContext.Current.Web;
            LabelTitle.Text = web.Title;
        }
    }
}

There is one more thing to do, exclude the selection of the authentication mode from your web.config file:

web.config:

<?xml version="1.0"?>

<configuration>
    <appSettings/>
    <connectionStrings/>
    <system.web>
        <compilation debug="true" />
        <!-- <authentication mode="Windows" /> -->
    </system.web>
</configuration>

 We can now run the page in the context of two different sites to see that it works:

Published Thursday, November 09, 2006 4:13 PM by svdoever
Filed under: SharePoint

Comments

# Serge van den Oever [Macaw] : SharePoint 2007 - _layouts, pages in site context, help!
Thursday, November 09, 2006 4:31 PM by Ishai Sagi
# re: SharePoint 2007 - /_layouts and how to create pages that run in site context

Did you try using that same page from another virtual directory running with a different application pool?

My tests show that if you do, it fails.

Friday, November 10, 2006 5:12 AM by svdoever
# re: SharePoint 2007 - /_layouts and how to create pages that run in site context

Hi Ishai,

Did you try to copy your code-behind dll to the bin directory of the SharePoint site in the other web application. I assume this works.

Serge

PS: You have a great weblog!

Monday, November 13, 2006 4:44 AM by Roni Hofer
# re: SharePoint 2007 - /_layouts and how to create pages that run in site context

Hi Serge,

Thanks for your great post! I'm currently investigating in the same area. I tried your proposition with a "web application project". It works fine. Until now I have two issues:

- myWeb.AllowUnsafeUpdates = true; throws an security exception (I think it's because the assembly has to be in "bin" instead of "app_bin" or GAC)

- Global.asax cannot be used

Before I tried the following way with two different VS projects: In the first project there are only .aspx files (in a subfolder of layouts). The second project is a class library with all the code behind and additional classes I need. In the .aspx files the reference to the code looks like this:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="Documena.DmAssistant.AppPages._Start, Documena.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=08e712e82e6eb11b" MasterPageFile="/_layouts/application.master" %>

The assembly may reside in "app_bin" or GAC.

Everything works fine (expect Global.asax). The big disadvantage of this solution: you have to define the controls of the .aspx pages in the class library manually.

Any comments are welcome!

Roni

Monday, November 13, 2006 9:34 PM by Ishai Sagi
# re: SharePoint 2007 - /_layouts and how to create pages that run in site context

I will have to try your suggestion, but I think the problem is the application pool.

Roni, you should not deploy to the app_bin folder. you should only work on the bin folder.

by the way, is this the same roni who worked for cellcom a few years back?

Thursday, November 30, 2006 10:20 AM by Ryan
# re: SharePoint 2007 - /_layouts and how to create pages that run in site context

How do you reference the microsoft.Sharepoint.dll? I get an error when i do it

Thursday, November 30, 2006 12:15 PM by ryan
# re: SharePoint 2007 - /_layouts and how to create pages that run in site context

i am getting the following error

Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed.

Any Ideas??

Monday, December 04, 2006 2:06 AM by Manish
# re: SharePoint 2007 - /_layouts and how to create pages that run in site context

Respected Sir

Manish here.

Sir i want ot nkow thet can we set the context at run time in share point assuming that we have got the url of a page by using parentweb property then we have to set this as a context at run time.

Thanks in Advance.

Bye.

Monday, December 04, 2006 2:58 PM by Ryan
# re: SharePoint 2007 - /_layouts and how to create pages that run in site context

The problem i had was with the WSS_minimal instead of WSS_medium in the web.config file it is working now but i am getting

Content controls have to be top-level controls in a content page or a nested master page that references a master page.

when i try to add a master page in the OnPreInit(EventArgs e) method

Monday, February 19, 2007 1:51 AM by anser
# re: SharePoint 2007 - /_layouts and how to create pages that run in site context

I've used this method to get current user information. But SPContext.Current.Web.CurrentUser.LoginName returns "SHAREPOINT/system". How to get logged in user?

Tuesday, April 17, 2007 12:33 PM by wasi
# re: SharePoint 2007 - /_layouts and how to create pages that run in site context

i am getting error ~/_layouts/application.master is not found

please reply

Tuesday, May 08, 2007 7:22 AM by Karthik
# re: SharePoint 2007 - /_layouts and how to create pages that run in site context

Thanks for the great post.

Did u ever try to deploy a web application that uses its own master page.

When I tried, I get an error message that says,

The referenced file '/MasterPages/TestMaster.master' is not allowed on this page.   at System.Web.UI.TemplateParser.ProcessError(String message)

  at System.Web.UI.BaseTemplateParser.GetReferencedType(VirtualPath virtualPath, Boolean allowNoCompile)

  at System.Web.UI.PageParser.ProcessMainDirectiveAttribute(String deviceName, String name, String value, IDictionary parseData)

  at System.Web.UI.TemplateParser.ProcessMainDirective(IDictionary mainDirective)

Please reply.

Wednesday, June 06, 2007 8:50 PM by James McDowell
# re: SharePoint 2007 - /_layouts and how to create pages that run in site context

I have built a number of Web Apps in my layouts directory, and they generally can be used from any site like this siteroot/.../page.aspx  but when I add a local, simple master page, then the web app only works from the site root, and not the sub sites.  I get the classic "Unknown Error".  Any thoughts?

Wednesday, August 08, 2007 5:05 AM by PrashanthSpark
# re: SharePoint 2007 - /_layouts and how to create pages that run in site context

How to create personal site using code

i need to create a personal site for all the users while iam creating userprofile's

wht is the object model i need to specify,

does personal site has tempalate..

Thursday, October 11, 2007 2:20 AM by Craig
# re: SharePoint 2007 - /_layouts and how to create pages that run in site context

Thanks alot! this post has saved my life. 2 days of trial and ERROR. You have no idea how cool this is! Thanks again!

YYYYEEEEEEEEESSSSSSSSSS

# Entradas imprescindibles para desarrollar aplicaciones dentro de sharepoint &laquo;

Pingback from  Entradas imprescindibles para desarrollar aplicaciones dentro de sharepoint &laquo;

Sunday, December 30, 2007 5:55 AM by negm.phlestin@gmail.com
# re: SharePoint 2007 - /_layouts and how to create pages that run in site context

i am getting the following error

Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed.

Any Ideas??

Thursday, February 14, 2008 2:36 PM by t_Kalpana@rediffmail.com
# re: SharePoint 2007 - /_layouts and how to create pages that run in site context

Hi,

We have developed web application that is copied to the _Layouts folder in SP and is IIS configured with Windows authentication. But I'm faced with big problem, Authentication. The application has different modules. I'm creating an ASP menu control on the home page of a site and where each menu item points to a module folder path on the SP server. The module should be restricted only to few users. Planning to create a group in SP. But I dont know how to authenticate the user in Page_Load event.

Any help would be greatly appreciated

 
内容概要:本文介绍了基于Python实现的SSA-GRU(麻雀搜索算法优化门控循环单元)时间序列预测项目。项目旨在通过结合SSA的全局搜索能力和GRU的时序信息处理能力,提升时间序列预测的精度和效率。文中详细描述了项目的背景、目标、挑战及解决方案,涵盖了从数据预处理到模型训练、优化及评估的全流程。SSA用于优化GRU的超参数,如隐藏层单元数、学习率等,以解决传统方法难以捕捉复杂非线性关系的问题。项目还提供了具体的代码示例,包括GRU模型的定义、训练和验证过程,以及SSA的种群初始化、迭代更新策略和适应度评估函数。; 适合人群:具备一定编程基础,特别是对时间序列预测和深度学习有一定了解的研究人员和技术开发者。; 使用场景及目标:①提高时间序列预测的精度和效率,适用于金融市场分析、气象预报、工业设备故障诊断等领域;②解决传统方法难以捕捉复杂非线性关系的问题;③通过自动化参数优化,减少人工干预,提升模型开发效率;④增强模型在不同数据集和未知环境中的泛化能力。; 阅读建议:由于项目涉及深度学习和智能优化算法的结合,建议读者在阅读过程中结合代码示例进行实践,理解SSA和GRU的工作原理及其在时间序列预测中的具体应用。同时,关注数据预处理、模型训练和优化的每个步骤,以确保对整个流程有全面的理解。
内容概要:本文详细介绍了如何使用PyQt5创建一个功能全面的桌面备忘录应用程序,涵盖从环境准备、数据库设计、界面设计到主程序结构及高级功能实现的全过程。首先,介绍了所需安装的Python库,包括PyQt5、sqlite3等。接着,详细描述了SQLite数据库的设计,创建任务表和类别表,并插入默认类别。然后,使用Qt Designer设计UI界面,包括主窗口、任务列表、工具栏、过滤器和日历控件等。主程序结构部分,展示了如何初始化UI、加载数据库数据、显示任务列表以及连接信号与槽。任务管理功能方面,实现了添加、编辑、删除、标记完成等操作。高级功能包括类别管理、数据导入导出、优先级视觉标识、到期日提醒、状态管理和智能筛选等。最后,提供了应用启动与主函数的代码,并展望了扩展方向,如多用户支持、云同步、提醒通知等。 适合人群:零基础或初学者,对Python和桌面应用程序开发感兴趣的开发者。 使用场景及目标:①学习PyQt5的基本使用方法,包括界面设计、信号与槽机制;②掌握SQLite数据库的基本操作,如创建表、插入数据、查询等;③实现一个完整的桌面应用程序,具备增删改查和数据持久化功能;④了解如何为应用程序添加高级特性,如类别管理、数据导入导出、到期日提醒等。 阅读建议:此资源不仅适用于零基础的学习者,也适合有一定编程经验的开发者深入理解PyQt5的应用开发。建议读者跟随教程逐步实践,结合实际操作来理解和掌握每个步骤,同时可以尝试实现扩展功能,进一步提升自己的开发技能。
<think>好的,我现在需要处理用户提供的编译错误信息。首先,用户执行了`mv -f libqquicklayoutsplugin.so ../../../qml/QtQuick/Layouts/libqquicklayoutsplugin.so`,然后遇到了make的错误退出,导致编译失败。错误信息显示在多个make步骤中出现了问题,最终的退出码都是2。 首先,我要理解这个mv命令的作用。看起来用户正在尝试将编译生成的.so文件移动到目标目录。这个移动操作可能是编译过程的一部分,或者是用户手动执行的步骤。接下来,make在离开不同目录时报告了错误,这可能意味着在编译过程中某个步骤没有正确完成,导致后续步骤无法继续。 可能的错误原因有几个方面: 1. **权限问题**:用户是否有足够的权限在目标目录中写入文件?如果目标目录`../../../qml/QtQuick/Layouts/`权限不足,mv命令会失败,导致后续make步骤出错。 2. **路径错误**:移动文件时使用的相对路径是否正确?用户当前所在的目录是否与预期一致?如果路径不正确,mv命令无法找到源文件或目标目录,导致文件移动失败。 3. **文件不存在**:源文件`libqquicklayoutsplugin.so`是否存在?如果编译过程中该文件未生成,mv命令会失败,进而导致make错误。 4. **构建过程中断**:之前的编译步骤是否有错误?如果编译在生成.so文件之前就已经失败,那么mv命令自然会失败,从而导致整个构建过程的中断。 接下来,我需要验证这些可能性。用户提供的错误信息显示make在多个步骤中退出,这可能意味着问题出现在更早的阶段。例如,在编译`libqquicklayoutsplugin.so`时可能已经出现了错误,导致该文件未被正确生成,因此mv命令失败。 此外,用户之前的问题是关于文件找不到的问题,可能之前的问题已经解决,但这次是在另一个阶段的错误。或者,之前的解决步骤可能没有完全解决根本问题,导致编译过程仍然存在问题。 需要建议用户检查编译日志,查看是否有更早的错误信息,尤其是在生成`libqquicklayoutsplugin.so`时的错误。此外,检查目标目录的权限和路径是否正确,确保文件可以被成功移动。 另外,用户可能需要重新运行编译命令,并观察输出,以确定具体的失败点。如果权限不足,可能需要使用sudo,或者在构建目录设置正确的权限。如果路径错误,需要调整相对路径或使用绝对路径。 最后,可能需要建议用户清理构建目录并重新编译,确保所有步骤从头开始,避免残留文件导致的问题。</think>$\textcolor{green}{\textbf{问题分析}}$ 您在执行Qt编译过程中遇到了文件移动失败导致的编译中断。关键信息如下: ```bash mv -f libqquicklayoutsplugin.so ../../../qml/QtQuick/Layouts/libqquicklayoutsplugin.so make[4]: 离开目录... # 后续多个make退出并报错 ``` 这表示`make`尝试将编译生成的动态库文件`libqquicklayoutsplugin.so`移动到目标路径时失败。 --- $\textcolor{blue}{\textbf{故障原因}}$ $\textbf{可能性1:文件路径错误}$ - 目标路径`../../../qml/QtQuick/Layouts/`可能不存在 - 使用相对路径时目录层级计算错误 $\textbf{可能性2:权限不足}$ - 目标目录`Layouts`可能没有写入权限 - 需检查目标目录归属: ```bash ls -ld ../../../qml/QtQuick/Layouts ``` $\textbf{可能性3:文件未生成}$ - 核心文件`libqquicklayoutsplugin.so`未成功编译 - 查看更早的编译日志是否有C++代码编译错误 --- $\textcolor{red}{\textbf{解决方法}}$ $\textbf{步骤1:验证目标路径}$ ```bash # 进入目标目录并检查是否存在 cd /home/yuerui/Qt/qt-build/qtdeclarative/src/imports/layouts ls -l ../../../qml/QtQuick/Layouts/ # 若目录不存在则手动创建 mkdir -p ../../../qml/QtQuick/Layouts ``` $\textbf{步骤2:检查权限}$ ```bash # 查看目录权限(应有rwx权限) stat ../../../qml/QtQuick/Layouts # 修复权限(如果需要) sudo chown -R $USER:$USER ../../../qml ``` $\textbf{步骤3:定位编译错误根源}$ ```bash # 重新编译并捕获详细日志 make sub-imports 2>&1 | tee build.log # 搜索关键词定位错误 grep -i "error:" build.log grep -i "libqquicklayoutsplugin" build.log ``` $\textbf{典型错误场景}$ - **C++语法错误**:查看日志中`.cpp`文件的编译错误 - **依赖缺失**:检查是否缺少QtQuick开发包 - **磁盘空间不足**: ```bash df -h /home # 确保至少有10GB剩余空间 ``` --- $\textcolor{orange}{\textbf{完整修复流程建议}}$ ```bash # 清理残留文件 cd /home/yuerui/Qt/qt-build make distclean # 重新配置(根据实际参数调整) ../qt-src/configure -prefix /usr/local/qt5 -opensource -confirm-license # 仅编译特定模块(节省时间) make module-qtdeclarative -j$(nproc) ``` $\textcolor{purple}{\textbf{预防措施}}$ 1. 编译前始终执行环境检查: ```bash qmake -v # 验证Qt版本 gcc --version # 检查编译器 ``` 2. 使用`ccache`加速重复编译: ```bash export PATH="/usr/lib/ccache:$PATH" ``` 3. 推荐使用[ninja](https://ninja-build.org/)替代make: ```bash ../qt-src/configure -platform linux-g++ -ninja ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值