Summary: Learn to use Microsoft Visual Studio 2005 to create a simple ASP.NET 2.0 Web site that you can deploy to the SharePoint layouts folder.
Applies to: 2007 Microsoft Office System, Microsoft Windows SharePoint Services 3.0, ASP.Net 2.0, Microsoft Visual Studio 2005
Joel Krist, iSoftStone
February 2008
Also putting the assembly of your web app in the GAC wasn't an option for me.
Finally I realized you could just place your web app's assembly into the bin folder of your SharePoint site. I came to this idea because I was already referencing assemblies there into my web app under layouts. Now al we have to do is set these paths in our WSP to make our feature work perfectly.
VS2008 -> Replace CodeBehind with CodeFile
This will help you a lot.
Thanks
RK
Hopefully this will allow me to do links to my blog where I've described everything: Link = 'http://gregorbowie.wordpress.com/?p=40&preview=true'
And when try to build it in visual studio it gives error saying myapp/layouts/application.master does not exist and could not load assembly Microsoft.Sharepoint.ApplicationPages or one of its dependencies.
[tfl - 14 11 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
SQL Server : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C&
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell : http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&
Protected
Sub Page_PreInit(ByVal sender AsObject, _ByVal e As System.EventArgs) HandlesMe.PreInit
'MyBase.OnPreInit(e)
Dim Web As SPWeb = SPContext.Current.Web
Dim strUrl AsString = _
Web.ServerRelativeUrl() +
"/_catalogs/masterpage/default.master"Me.MasterPageFile = strUrl
EndSub
For this to pick up the code behind correctly in VS 2008, I had to make this change in my aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="YourNameSpace.YourClassName" MasterPageFile = "~/_layouts/application.master" %>
The changes are the CodeFile and the Inherits attribute. The CodeBehind attribute did not work for me, but CodeFile did. Furthermore, the Inherits tag had to be the full namespace/classname of your class.
The @Page attributes can be found here : http://msdn.microsoft.com/en-us/library/ydy4x04a.aspx
How can you get a good compile if you have an error on the ASP page. The masterPageFile specifies a page that does not exist. I even added a temporary master page file, and still could not get this to work.
[tfl - 03 08 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at
http://www.microsoft.com/communities/newsgroups/en-us/
. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C
&
SQL Server :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C
&
.NET Framework :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell :
http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
All Public :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C
&
itried this in Visual Studio 2005 and 2008 , and get same error "_layouts/application.master' does not exist"
and also another error: ould not load file or assembly 'Microsoft.SharePoint.ApplicationPages
even though i have added areference to SharePoint dll, and i am also developing directly at SharePoint Server
Any help is appriciated
I fellowed same directions in VS 2005 and VS 2008 too.. Still landing to HTTP 403 Forbidden page.
Can any one help me.
Update:
I tried in VS2005 and It worked.
Thanks
Lavu
[tfl - 03 08 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at
http://www.microsoft.com/communities/newsgroups/en-us/
. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C
&
SQL Server :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C
&
.NET Framework :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell :
http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
All Public :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C
&
It worked for me
But, there is a problem in the code
Dim strUrl As String = _
Web.ServerRelativeUrl(+"/_catalogs/masterpage/default.master")
it should be
Dim strUrl As String = _
Web.ServerRelativeUrl + "_catalogs/masterpage/default.master"
After I made that change, it worked
Hi,
I followed the instruction given on this page and created the sample web app. I copied the folder to the server where there is sharepoint running. when I browse, it shows http://localhose/_layouts/sptestapp/default.aspx in the URL. And displays an error saying "File Not Found"
Please point me where I could have gone wrong.
Thanks,
tj
[tfl - 03 08 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at
http://www.microsoft.com/communities/newsgroups/en-us/
. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C
&
SQL Server :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C
&
.NET Framework :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell :
http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
All Public :
http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C
&
Any bug fixes for this article?
[tfl - 03 08 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at
http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
SQL Server : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C&
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell : http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&
i have done the exact same thing........but it doesn't work for me...........it shows an error "Unknown Error " while i trying to run on my Sharepoint Site
[tfl - 03 08 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at
http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
SQL Server : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C&
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell : http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&
ProtectedSub Page_PreInit(ByVal sender AsObject, _
ByVal e As System.EventArgs) HandlesMe.PreInit
'MyBase.OnPreInit(e)
Dim Web As SPWeb = SPContext.Current.Web
Dim strUrl AsString = _
Web.ServerRelativeUrl() + "/_catalogs/masterpage/default.master"
Me.MasterPageFile = strUrl
EndSub
Thanks,
http://www.ozgrid.com/forum/showthread.php?t=88208
Good luck
TestAspx1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestAspx1.aspx.cs" Inherits="TestAspx.TestAspx1" MasterPageFile="../_layouts/application.master" %>
<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderMain" runat="server">
<div>
Page Title: <asp:Label ID="LabelTitle" runat="server" Text="Label">
</asp:Label>
</div>
</asp:Content>
<asp:Content ID="Content2"
ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">
Test ASP.NET 2.0 Application
</asp:Content>
TestAspx1.aspx,cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace TestAspx
{
public partial class TestAspx1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SPWeb web = SPContext.Current.Web;
LabelTitle.Text = web.Title;
}
protected override void OnPreInit( EventArgs e)
{
base.OnPreInit(e);
//SPWeb mySite = SPControl.GetContextWeb(Context);
SPWeb Web = SPContext.Current.Web;
this.MasterPageFile = Web.MasterUrl;
}
}
}
Steps I have done to run this webpage under the current sharepoint site.
1. copy the .aspx page on Layout folder (under 12 hive).
2.Give Strong name to the project.
3.Copy the dll into GAC
4.IISReset
5. try to run this page...... http://ost-dclb-shrp/_layouts/TestAspx1.aspx
get the error(shown below)
Error in sharepoint Log
spHttpHandler:GetHash finished
PublishingHttpModule.Init() calling AppDomainUnloadListener.Register()
AppDomainUnloadListener.RegisterSelf() entered lock(this=15368010)
Setting IIS virtual directory path to 'C:\Program Files\Microsoft Office Servers\12.0\WebServices\Root'.
Looking up IIS application pool id 'OfficeServerApplicationPool'.
Creating application 'Office Server Web Application' in application pool 'OfficeServerApplicationPool'.
Setting script maps to '.asax,c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG;.asmx,c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG;.config,c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG'.
Committing virtual directory 'root'.
IIS virtual directory 'root' provisioned on web site 'Office Server Web Services'.
Exception Type: System.Web.HttpException Exception Message: Could not load type 'TestAspx.TestAspx1'.
I am struggleing in this code ...for the last 2 days..Still not get any solutions....Any help will be appriciated......
Thanks,
Anurag
So I trashed it and tried again with File->New->Web Site and chose the "ASP.NET Web Site" template and that worked fine (just like the directions above said they would!).
I'm too lazy right now to figure out the difference between these two project templates, but I'm guessing there's something in the web.config that messes things up. Ideas, anyone?
Cheers!
-Denis
I believe you guys are probably not commenting out the <authentication> tag in the web.config.
I puzzled over this for a couple of hours because it was close to what I wanted, with a bit of tweaking it now works (at least for me, no promises).
It boiled down to removing the project name prefix from the "Inherits" part of the <%@ Page %> directive. (Note my project is called WSS01).
It used to read:
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="default.aspx.vb" Inherits="WSS01._Default" MasterPageFile="~/_layouts/application.master" %>
It now reads:
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="default.aspx.vb" Inherits="_Default" MasterPageFile="~/_layouts/application.master" %>
Turns out this was the only change needed for it to work, up until then I continually got the "Unknown Error " problem mentioned above.
Also, there's no need to build the project, deploy DLL's anywhere or touch the GAC. Any changes to the codebehind are immediately available next time you hit the page.
Here's the complete code for the ASPX page:
<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="default.aspx.vb" Inherits="_Default" MasterPageFile="~/_layouts/application.master" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ID="Content2" ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">
Test ASP.NET 2.0 Application
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderMain" runat="server">
<div>
Title of this site: <asp:Label ID="LabelTitle" runat="server" Text="Label"></asp:Label>
</div>
</asp:Content>
, I've now got confidence that I'll have something to show
Thanks for keeping it simple !
UPDATE: Yes, I was missing something.. no need to compile. Imclude the cs file in the deployment and it will get compiled on the fly. Works well as described above.
<Update>
I had to create a custom master page within Studio and point the page to it and copy it across with the other files
</Update>
Note:
