简体   繁体   English

我将在哪里将Page_Load的代码放在MVC SharePoint 2013提供程序托管的应用程序中?

[英]Where would I put the code for Page_Load in an MVC SharePoint 2013 provider hosted app?

I have some code from an ASP.NET Web Application that is currently in a Page_Load event in one of the Pages. 我有一些来自ASP.NET Web应用程序的代码,该代码当前在页面之一中的Page_Load事件中。 I'd like to move that code to a new ASP.NET MVC application I'm currently developing for accessing a SharePoint 2013 server. 我想将该代码移到我当前正在开发的用于访问SharePoint 2013服务器的新ASP.NET MVC应用程序中。 However, I know that the Page_Load event doesn't exist in MVC. 但是,我知道在MVC中不存在Page_Load事件。 Is there a certain event and/or Controller method I can use for this purpose? 我是否可以为此使用某种事件和/或控制器方法?

For clarification, the code I'm moving would be executed before any Controller logic is executed. 为了澄清起见,我要移动的代码将在执行任何Controller逻辑之前执行。 The code is to check for SharePoint tokens prior to allowing the user to call any Controller methods. 该代码用于在允许用户调用任何Controller方法之前检查SharePoint令牌。

Any help would be appreciated. 任何帮助,将不胜感激。

Put that code into a custom Authorize Action Filter. 将该代码放入自定义的“授权操作过滤器”中。

https://msdn.microsoft.com/en-us/library/gg416513(VS.98).aspx https://msdn.microsoft.com/zh-CN/library/gg416513(VS.98).aspx

public class CustomAuthorizationFilter : ActionFilterAttribute
{

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {

        //your authorization code goes here.

        base.OnActionExecuting(filterContext);
    }


}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM