按下yahoo / outlook日历API

时间:2019-02-26 11:26:25

标签: c# asp.net-mvc session session-state httpsession

public async Task<ActionResult> YahooCalendar(int id, string start, string end)
    {
        Event_ViewModel eventDetails = _ieventService.GetEventDetailsById(id);
        DataAccess.event_dates eventObject = new DataAccess.event_dates();
        eventObject.event_date_start = Convert.ToDateTime(start);
        eventObject.event_date_stop = Convert.ToDateTime(end);
        eventObject.event_date_place = eventDetails.event_place;
        string eventInfo1 = eventDetails.event_infotext != null ? eventDetails.event_infotext : eventDetails.event_public_info;
        eventObject.event_date_info = eventDetails.event_name + eventInfo1;

        Session["eventObjYahoo"] = eventObject;
        Session["yahooEventName"] = eventDetails.event_name;
        Session["eventURL"] = Request.ServerVariables["HTTP_REFERER"];
        string clientId = ConfigurationManager.AppSettings["YahooClientId"];
        string clientSecret = ConfigurationManager.AppSettings["YahooClientSecret"];
        string redirectUrl = ConfigurationManager.AppSettings["YahooRedirectURL"];
        var url = "https://api.login.yahoo.com/oauth2/request_auth?client_id="+clientId+"&redirect_uri="+redirectUrl+"&response_type=code&language=en-us";
        return Redirect(url);
    }

    [HttpGet]
    public async Task<ActionResult> YahooAuth(string code)
    {
        DataAccess.event_dates eventObject = (DataAccess.event_dates)Session["eventObjYahoo"];
        string clientId = ConfigurationManager.AppSettings["YahooClientId"];
        string clientSecret = ConfigurationManager.AppSettings["YahooClientSecret"];
        String encoded = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(clientId + ":" + clientSecret));

        var client = new RestClient("https://api.login.yahoo.com/oauth2/get_token");
        var request = new RestRequest(Method.POST);
        request.AddHeader("Authorization", "Basic " + encoded);
        request.AddHeader("content-type", "application/x-www-form-urlencoded");
        request.AddParameter("grant_type", "authorization_code");
        request.AddParameter("redirect_uri", "oob");
        request.AddParameter("code", code);
        IRestResponse response = client.Execute(request);

        string eventStart = Convert.ToDateTime(eventObject.event_date_start).ToString("yyyyMMddTHHmmss");
        string eventStop = Convert.ToDateTime(eventObject.event_date_stop).ToString("yyyyMMddTHHmmss");

        string eventName = Session["yahooEventName"].ToString();
        string eventUrl = Session["eventURL"].ToString();

        var calURL = "http://calendar.yahoo.com/?v=60&TITLE=Eventry&DESC="+eventObject.event_date_info+"&ST="+eventStart+"&ET="+eventStop+"&in_loc="+eventObject.event_date_place";

        return Redirect(calURL);
    }

单击日历按钮后,我转到YahooCalendar,在其中获取所有事件信息并将其存储在会话中。然后在获得授权后,我将重定向到YahooAuth,从会话中检索值并将其发布到yahoo日历。

此功能在本地和登台服务器上正常工作,但是在生产服务器(活动站点)上,会话状态已过期,并且出现“对象未设置为对象实例”错误。

任何人都知道为什么它可以在本地/舞台上运行,但不能在现场运行,以及如何在现场保持会话状态?任何帮助将不胜感激。

0 个答案:

没有答案