简体   繁体   中英

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. I'd like to move that code to a new ASP.NET MVC application I'm currently developing for accessing a SharePoint 2013 server. However, I know that the Page_Load event doesn't exist in MVC. 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. The code is to check for SharePoint tokens prior to allowing the user to call any Controller methods.

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

public class CustomAuthorizationFilter : ActionFilterAttribute
{

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {

        //your authorization code goes here.

        base.OnActionExecuting(filterContext);
    }


}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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