Why do ASP. NET applications need to be embedded in SharePoint? We will not discuss this! We will discuss how to embed ASP. NET applications into SharePoint and possible problems.
Body start:
Here we create a Web application with a Demo. aspx page. The Code is as follows:
- namespace WebInMOSS
- {
- public partial class _Demo: System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- Response.Write("Web Can In Moss");
- }
- }
- }
Compile this program, generate a WebInMOSS. dll file, copy the dll to the bin folder under the website directory, and add nodes:
- <SafeControl Assembly="WebInMOSS, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null" Namespace="WebInMOSS" TypeName="*" Safe="True" />
Then, add the Demo. aspx page to the MOSS. You can choose to use SPD or directly upload the document library. Here we put it in "Pages. View pages/Demo. aspx in MOSS. Can I delete autoeventwireup? Indeed, the Web Can In Moss is displayed on the page after AutoEventWireup = "true" is deleted, proving that the execution is successful. To increase the complexity of web applications, put a button in Demo. aspx. The event is as follows:
- Protected void Button3_Click (object sender, EventArgs e)
- {
- SPSiteSiteCollection=NewSPSite ("http: // xuwei: 8080 ");
- SPWebSite=SiteCollection. OpenWeb ("/Docs /");
- SPListList=Site. Lists ["notification"];
- SPListItemCollectionItems=List. Items;
- Foreach (SPListItem item in items)
- {
- Response. Write ("<Br/>");
- Response. Write (item ["Title"]. ToString ());
- }
- }
Debugging results in VS2005 (ignore the write session and read session Buttons First ):
Recompile the program dll, Demo. aspx, and put it in the MOSS. The Onclick event cannot be used again. How can this problem be solved? We must start the MOSS security mode to execute server-side events. The procedure is as follows:
Find the <SharePoint> node in the Web. config file and go to <PageParserPaths> </PageParserPaths>
Add a virtual path under the node <PageParserPath VirtualPath = "/*" CompilationMode = "Always" AllowServerSideScript = "true" IncludeSubFolders = "true"/>
Declare that all files on the site Allow server events. You can also specify the folder where the virtual directory is, but the value must be ~ // Or/, and must end with a file name or.
Save Demo. aspx and browse the page. The page will be displayed normally. Click the listobject button (ignore the write session and read session Buttons First). OK. It will be displayed normally!
Once again, it increases the complexity of web applications and adds sessions. No matter which method is used in MOSS development, as long as it is integrated with its own programs, it will always encounter Session problems ).
The Code is as follows:
- protected void Button1_Click(object sender, EventArgs e)
- {
- Session["Count"] = "1";
- }
- protected void Button2_Click(object sender, EventArgs e)
- {
- if (Session["Count"] != null)
- {
- Response.Write("<br><font color=red>"+Session["Count"].ToString()+"</font>");
- }
- }
After compilation and storage, browse the page again and click the listobject button to display the result normally. However, when you click Write Session, this prompt is domineering! What is an unexpected error! I tried to modify <customErrors mode = "Off"/> to display an error message to MOSS, but failed. No trace is found for searching the Log file. Fortunately, it is expected that the Session may be faulty at the beginning. Check Web. config to find
- <pages enableSessionState="false" enableViewState="true" enableViewStateMac=
"true" validateRequest="false" pageParserFilterType="Microsoft.SharePoint.
ApplicationRuntime.SPPageParserFilter, Microsoft.SharePoint, Version=12.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c" asyncTimeout="7">
The Session is disabled by default and cannot be executed normally. Set it to true and save it. Go to the demo. aspx page and click write session and read Session to run properly. The preceding section describes how to embed ASP. NET applications.
- ASP. NET calls the WCF Service
- Analysis of ASP. NET verification controls
- Compatibility between the WCF Service and ASMX service in ASP. NET
- ASP. NET Applications
- ASP. NET HttpModule