本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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"));
}