当前位置: 首页>>代码示例>>C#>>正文


C# UrlHelper.ToPublicUrl方法代码示例

本文整理汇总了C#中System.Web.Mvc.UrlHelper.ToPublicUrl方法的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper.ToPublicUrl方法的具体用法?C# UrlHelper.ToPublicUrl怎么用?C# UrlHelper.ToPublicUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Mvc.UrlHelper的用法示例。


在下文中一共展示了UrlHelper.ToPublicUrl方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FbAuth

        public ActionResult FbAuth(string returnUrl)
        {
            var client = new FacebookClient();
                    try
                    {
                        var oauthResult = client.ParseOAuthCallbackUrl(Request.Url);

                        // Build the Return URI form the Request Url
                        var redirectUri = new UriBuilder(Request.Url);
                        redirectUri.Path = Url.Action("FbAuth", "Account");

                        //Get the Public Uri due to apphabor getting all "cloudy" with ports
                        var urlHelper = new UrlHelper(Request.RequestContext);
                        var publicUrl = urlHelper.ToPublicUrl(redirectUri.Uri);

                        // Exchange the code for an access token
                        dynamic result = client.Get("/oauth/access_token", new
                        {
                            client_id = ConfigurationManager.AppSettings["FacebookAppId"],
                            redirect_uri = publicUrl,
                            client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
                            code = oauthResult.Code,
                        });

                        // Read the auth values
                        string accessToken = result.access_token;
                        DateTime expires = DateTime.UtcNow.AddSeconds(Convert.ToDouble(result.expires));

                        // Get the user's profile information
                        dynamic me = client.Get("/me",
                                      new
                                      {
                                          fields = "first_name,last_name,email",
                                          access_token = accessToken
                                      });

                        //Instantiate FbModel
                        var model = new FbModel();

                        // Read the Facebook user values
                        model.FacebookId = Convert.ToInt64(me.id);
                        model.FirstName = me.first_name;
                        model.LastName = me.last_name;
                        model.Email = me.email;

                        // Add the user to our persistent store
                        var user = AccountService.AddOrUpdateFacebookUser(model);

                        //Check if the account requires the password to be set
                        if (string.IsNullOrEmpty(user.Email))
                        {

                            return RedirectToAction("RegisterFacebook", "Account", new { @code = user.AccountHash });
                        }
                        else
                        {
                            AuthenticateUser(user.Id, user.FirstName, user.LastName, user.Email, user.FacebookId, user.AccessToken);
                            return RedirectToAction("Index", "Home");
                        }

                    }
                    catch (Exception ex)
                    {
                        Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                    }

                    return RedirectToAction("Content", "Error");
        }
开发者ID:jamesamuir,项目名称:FacebookAuth,代码行数:68,代码来源:AccountController.cs

示例2: SignUpFacebook

        public ActionResult SignUpFacebook()
        {
            // Build the Return URI form the Request Url
                var redirectUri = new UriBuilder(Request.Url);
                redirectUri.Path = Url.Action("FbAuth", "Account");

                //Get the Public Uri due to apphabor getting all "cloudy" with ports
                var urlHelper = new UrlHelper(Request.RequestContext);
                var publicUrl = urlHelper.ToPublicUrl(redirectUri.Uri);

                var client = new FacebookClient();

                #region Facebook OAuth URL example
                // Generate the Facebook OAuth URL
                // Example: https://www.facebook.com/dialog/oauth?
                //                client_id=YOUR_APP_ID
                //               &redirect_uri=YOUR_REDIRECT_URI
                //               &scope=COMMA_SEPARATED_LIST_OF_PERMISSION_NAMES
                //               &state=SOME_ARBITRARY_BUT_UNIQUE_STRING
                #endregion

                //Create the Facebook Oauth URL
                var uri = client.GetLoginUrl(new
                {
                    client_id = ConfigurationManager.AppSettings["FacebookAppId"],
                    redirect_uri = publicUrl,
                    scope = "email",
                });

                return Redirect(uri.ToString());
        }
开发者ID:jamesamuir,项目名称:FacebookAuth,代码行数:31,代码来源:AccountController.cs


注:本文中的System.Web.Mvc.UrlHelper.ToPublicUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。