SharePoint 2010中HTTP处理程序的问题
-
16-10-2019 - |
题
我正在为SharePoint 2010开发视觉网络部分。此Webpart需要通过Ajax获取一些数据。所以我去了HTTP处理程序 + jQuery解决方案 这里.
但是在尝试访问处理程序时,我会遇到问题。我得到了著名的.NET错误页面:
服务器错误中的“/”应用程序中的错误。运行时错误描述:服务器上发生了一个应用错误。此应用程序的当前自定义错误设置阻止应用程序错误的详细信息远程查看(出于安全原因)。但是,可以通过在本地服务器计算机上运行的浏览器来查看它。
详细信息:要启用此特定错误消息的详细信息,以便在远程计算机上查看,请在当前Web应用程序的根目录中的“ Web.config”配置文件中创建标签。然后,此标签应将其“模式”属性设置为“关闭”。
注意:您看到的当前错误页面可以通过修改应用程序配置标签的“ defaultredirect”属性来替换一个自定义错误页面,以指向自定义错误页面URL。
因此,我检查了服务器的事件查看器,以查看错误的详细信息。这就是导致它的原因:
Event code: 3006
Event message: A parser error has occurred.
Event time: 8/4/2011 2:08:17 PM
Event time (UTC): 8/4/2011 6:08:17 PM
Event ID: 71c80726be98453ab77a7c1d474cbf7c
Event sequence: 5
Event occurrence: 2
Event detail code: 0
Process information:
Process ID: 6200
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE
Exception information:
Exception type: HttpParseException
Exception message: Could not create type 'MyNamespace.MyHandler'.
Request information:
Request URL: http://mysharepointurl/_layouts/MyNamespace/MyHandler.ashx
Request path: /_layouts/MyNamespace/MyHandler.ashx
User host address: xxx.xxx.xxx.xxx
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITY\NETWORK SERVICE
Thread information:
Thread ID: 11
Thread account name: NT AUTHORITY\NETWORK SERVICE
Is impersonating: True
Stack trace: at System.Web.UI.SimpleWebHandlerParser.GetType(String typeName)
at System.Web.UI.SimpleWebHandlerParser.GetTypeToCache(Assembly builtAssembly)
at System.Web.Compilation.SimpleHandlerBuildProvider.GetGeneratedType(CompilerResults results)
at System.Web.Compilation.BuildProvider.CreateBuildResult(CompilerResults results)
at System.Web.Compilation.BuildProvider.GetBuildResult(CompilerResults results)
at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.UI.SimpleHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
at System.Web.UI.SimpleHandlerFactory.GetHandler(HttpContext context, String requestType, String virtualPath, String path)
at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
这是myhandler.ashx
<%@ WebHandler Language="C#" Class="MyNamespace.MyHandler" CodeBehind="MyHandler.cs" %>
如您所见,我错过了 Assembly
指示。但是我不知道该放什么。 我在哪里得到键控,姓名等?
解决方案
我最终打开了Visual Studio命令提示。导航到我的Web部件的bin/Release文件夹,并使用 sn -t 命令我的DLL获取令牌!
其他提示
在Visual Studio中,学会喜欢可用的SharePoint令牌。在这里阅读有关它们的更多信息: http://www.andrewconnell.com/blog/archive/2009/12/12/03/sharepoint-2010-dev-tidbit-use-th-the-the-tokens-in--visual.aspx
我今天使用一个单独的.ASHX文件和.cs文件做了同样的事情,它对我有用。我遇到了同样的错误,但随后注意到我犯了一个班级名称错误。这是我的代码:
*****DemoHandler.cs********
using System;
using System.Web;
using Microsoft.SharePoint;
namespace CustomHTTPModule
{
public class DemoHandler : IHttpHandler
{
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
SPSite siteColl = SPContext.Current.Site;
SPWeb site = SPContext.Current.Web;
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World from " +
site.Title +
" at " +
site.Url);
}
}
}
*********DemoHandler.ashx*******************
<%@ Assembly Name="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Assembly Name="CustomHTTPModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9eec5e2ad94ff809" %>
<%@ WebHandler Language="C#" Class="CustomHTTPModule.DemoHandler" CodeBehind="DemoHandler.cs" %>
我在VS 2010中选择了一个空的SharePoint项目,请访问下面的博客以获取项目结构的图像
单击部署它应将您的自定义HTTPMODULE DLL部署到GAC,并将.ASHX和.ASHX部署到Web应用程序的_layouts。http://webappname/sites/sitename/customhttpmodule/demohandler.ashx“应该给您文字,并带有我提到的网站名称 http://blogs.msdn.com/b/kaevans/archive/2010/08/04/deploying-an-asp-net-httphandler-the-sharepoint-2010.aspx
快速而肮脏的方法?将组件放在GAC中,并在其上获取属性。一旦拥有所需的东西,就可以右键单击卸载它。
更新(15JAN13):
您还可以将外部工具添加到Visual Studio中,以帮助解决此问题(工具 - >外部工具...):
Title: Get Assembly Name
Command: powershell.exe
Arguments: -command "[System.Reflection.AssemblyName]::GetAssemblyName(\"$(TargetPath)\").FullName"
Use Output Window: checked
运行命令时,输出窗口将显示这样的内容:
YourAsseMblyName,版本= 1.0.0.0,Culture =中性,publicKeyToken = 9999D8E77777777F66
您可以为强名称工具做同样的事情:
Title: Get Strong Name Token
Command: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\sn.exe
Arguments: -T $(TargetPath)
Use Output Window: checked
在输出窗口中显示这样的内容:
Microsoft(R).NET Framework强名称实用程序版本3.5.30729.1版权所有(C)Microsoft Corporation。版权所有。
公钥令牌是9999D8E7777777F66