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


C# UrlHelper.ToAbsoluteUrl方法代码示例

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


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

示例1: SendActivation

        public EmailSendAttempt SendActivation(RequestContext request, User u)
        {
            var template = LoadTemplate(
                "template-user-activation",
                request.HttpContext.Server.MapPath("~/Messages/UserActivation.template")
            );
            var url = new UrlHelper(request).Action(MVC.Public.Login.Activate(u.ActivationCode));
            var e = Builder.Transform(
                template,
                new TemplateData
                    {
                        {"login", u.Login},
                        {"program", Application.ProgramName},
                        {"url", url.ToAbsoluteUrl(request.HttpContext.Request).ToString() },
                    },
                request.HttpContext.Request
            );
            e.Recipient = new EmailAddress {Address = u.Email, Name = u.DisplayName};

            var attempt = Sender.Send(e);
            if (attempt.Success)
            {
                u.LastActivationEmailSent = DateTime.UtcNow;
                UserRepository.Save(u);
            }
            return attempt;
        }
开发者ID:nicknystrom,项目名称:AscendRewards,代码行数:27,代码来源:UserMessaging.cs

示例2: SendReset

 public EmailSendAttempt SendReset(RequestContext request, User u, string password)
 {
     var template = LoadTemplate(
         "template-user-reset",
         request.HttpContext.Server.MapPath("~/Messages/UserReset.template")
     );
     var url = new UrlHelper(request).Action(MVC.Public.Login.Index());
     var e = Builder.Transform(
         template,
         new TemplateData
             {
                 {"login", u.Login},
                 {"program", Application.ProgramName},
                 {"password", password},
                 {"url", url.ToAbsoluteUrl(request.HttpContext.Request).ToString() },
             },
         request.HttpContext.Request
     );
     e.Recipient = new EmailAddress { Address = u.Email, Name = u.DisplayName };
     return Sender.Send(e);
 }
开发者ID:nicknystrom,项目名称:AscendRewards,代码行数:21,代码来源:UserMessaging.cs

示例3: SendAward

 public EmailSendAttempt SendAward(RequestContext request, UserAward award)
 {
     var template = LoadTemplate(
         "template-user-award",
         request.HttpContext.Server.MapPath("~/Messages/UserAward.template")
     );
     var recipient = Users[award.Recipient];
     var nominator = Users[award.Nominator];
     var url = new UrlHelper(request).Action(MVC.Public.Award.Index(award.Document.Id));
     var e = Builder.Transform(
         template,
         new TemplateData
             {
                 {"program", Application.ProgramName},
                 {"url", url.ToAbsoluteUrl(request.HttpContext.Request).ToString() },
                 {"recipient", recipient.DisplayName},
                 {"nominator", nominator.DisplayName}
             },
         request.HttpContext.Request
     );
     e.Recipient = new EmailAddress { Address = recipient.Email, Name = recipient.DisplayName };
     return Sender.Send(e);
 }
开发者ID:nicknystrom,项目名称:AscendRewards,代码行数:23,代码来源:UserMessaging.cs

示例4: ToAbsoluteUrl_UrlHelperRequestContextIsNull_ThrowsException

        public void ToAbsoluteUrl_UrlHelperRequestContextIsNull_ThrowsException()
        {
            var urlHelper = new UrlHelper();
            // It is not possible to set UrlHelper.RequestContext to null and at the same time to have RouteCollection being not null.
            // Therefor this little trick to pass the null check for the urlHelper.RouteCollection.

            urlHelper.GetType().GetProperty("RouteCollection").GetSetMethod(true).Invoke(urlHelper, new object[] { new RouteCollection() });
            Assert.That(urlHelper.RouteCollection, Is.Not.Null);

            var parameterName = Assert.Throws<ArgumentNullException>(() => urlHelper.ToAbsoluteUrl("/some/relative/url")).ParamName;
            Assert.That(parameterName, Is.EqualTo("urlHelper.RequestContext"));
        }
开发者ID:hudo,项目名称:SwissKnife,代码行数:12,代码来源:UrlHelperExtensionsTests.cs


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