SharePoint 2007虚拟目录中的MVC4(Web API)控制器错误:拒绝访问(MVC4 (Web API) controller in SharePoint 2007 Virtual Di

编程入门 行业动态 更新时间:2024-10-24 18:27:25
SharePoint 2007虚拟目录中的MVC4(Web API)控制器错误:拒绝访问(MVC4 (Web API) controller in SharePoint 2007 Virtual Directory Error: Access is Denied)

我有一个ASP.NET 4应用程序,我在我的SharePoint站点的虚拟目录中。 这是一个自己的应用程序池中的自包含应用程序,所以我不认为SP是问题但是? aspx页面工作正常,但是对ApiController的请求返回401错误:Access是Deniend。

<html><head><title>Error</title></head><body>Error: Access is Denied.</body></html>

事件查看器什么也没有,IIS日志显示401 2 2148074254然后401 1 0然后200 0 0然后401 1 2148074248.我知道最后401.1看起来像我的错误,但我已经多次确认它是请求的最后一个日志条目。 适用于IE8,Chrome,FireFox。

Fiddler只显示401,“WWW-Authenticate:NTLM”与“WWW-Authenticate:NTLM TlRMblah_blah_blah ......”和上面的HTML交替显示。

备份计划是放弃控制器并使用.ashx,但希望SO可以提供帮助。

I have an ASP.NET 4 app that I have in a virtual directory in my SharePoint site. This is a self contained app in its own app pool so I don't think SP is the problem but? The aspx page works fine, but a request to the ApiController returns 401 Error: Access is Deniend.

<html><head><title>Error</title></head><body>Error: Access is Denied.</body></html>

Event Viewer has nothing and IIS log shows 401 2 2148074254 then 401 1 0 then 200 0 0 then 401 1 2148074248. I Know that last 401.1 looks like my mistake, but I have confirmed many times it is the Last log entry for a request. Consistant in IE8, Chrome, FireFox.

Fiddler shows only 401s, "WWW-Authenticate: NTLM" alternating with "WWW-Authenticate: NTLM TlRMblah_blah_blah..." and the HTML above.

Backup plan is to ditch the controller and use a .ashx, but hopefully SO can help.

最满意答案

找到解决方法,直到项目不再在SharePoint中。 保持Controler类(PSSController)原样,但添加了一个带有以下代码的ashx文件并更改了javascript以使用它。 cntrl只是我的班级; 你的QueryString和Post params会有所不同。 有点hacky但它​​的工作:)

using System; using System.Collections.Generic; using System.Web; using System.Web.SessionState; using Newtonsoft.Json; namespace PipWebApp { public partial class PSSurvey2API : IHttpHandler, IRequiresSessionState { public void ProcessRequest(HttpContext context) { String InputString = null; using (var sr = new System.IO.StreamReader(context.Request.InputStream)) InputString = sr.ReadToEnd(); List<PSSurvey.cntrl> cntrls = (List<PSSurvey.cntrl>)JsonConvert.DeserializeObject(InputString, typeof(List<PSSurvey.cntrl>)); String Params = context.Request.QueryString["Params"]; Controllers.PSSController APICon = new Controllers.PSSController(); if (context.Request.QueryString["Rpt"] == null) context.Response.Write(JsonConvert.SerializeObject(APICon.Post(cntrls, Params))); else context.Response.Write(JsonConvert.SerializeObject(APICon.Post(cntrls, context.Request.QueryString["Rpt"], Params))); } public bool IsReusable { get { return false; } } }

}

Found a work-around until the project is no longer in SharePoint. Kept the Controler class (PSSController) as-is, but added an ashx file with the below code and changed the javascript to use it. cntrl is just my class; your QueryString and Post params will be different. A bit hacky but it works :)

using System; using System.Collections.Generic; using System.Web; using System.Web.SessionState; using Newtonsoft.Json; namespace PipWebApp { public partial class PSSurvey2API : IHttpHandler, IRequiresSessionState { public void ProcessRequest(HttpContext context) { String InputString = null; using (var sr = new System.IO.StreamReader(context.Request.InputStream)) InputString = sr.ReadToEnd(); List<PSSurvey.cntrl> cntrls = (List<PSSurvey.cntrl>)JsonConvert.DeserializeObject(InputString, typeof(List<PSSurvey.cntrl>)); String Params = context.Request.QueryString["Params"]; Controllers.PSSController APICon = new Controllers.PSSController(); if (context.Request.QueryString["Rpt"] == null) context.Response.Write(JsonConvert.SerializeObject(APICon.Post(cntrls, Params))); else context.Response.Write(JsonConvert.SerializeObject(APICon.Post(cntrls, context.Request.QueryString["Rpt"], Params))); } public bool IsReusable { get { return false; } } }

}

更多推荐

本文发布于:2023-08-04 10:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1414043.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制器   错误   目录中   Web   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!