本文整理汇总了C#中System.Web.Mvc.UrlHelper.IsLocalUrl方法的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper.IsLocalUrl方法的具体用法?C# UrlHelper.IsLocalUrl怎么用?C# UrlHelper.IsLocalUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.UrlHelper
的用法示例。
在下文中一共展示了UrlHelper.IsLocalUrl方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public ActionResult Process(HttpContextBase context, AuthenticateCallbackData model)
{
if (model.Exception != null)
throw model.Exception;
var client = model.AuthenticatedClient;
var username = client.UserInformation.UserName;
FormsAuthentication.SetAuthCookie(username, false);
context.Response.AppendCookie(new HttpCookie("AccessToken", client.AccessToken.SecretToken)
{
Secure = !context.IsDebuggingEnabled,
HttpOnly = true
});
var urlHelper = new UrlHelper(((MvcHandler)context.Handler).RequestContext);
var redirectUrl = string.Format("/{0}/", username);
var cookie = context.Request.Cookies["returnUrl"];
if (cookie != null && urlHelper.IsLocalUrl(cookie.Value))
{
redirectUrl = cookie.Value;
cookie.Expires = DateTime.Now.AddDays(-1);
context.Response.Cookies.Add(cookie);
}
return new RedirectResult(redirectUrl);
}
示例2: SafeRedirectUrl
public static string SafeRedirectUrl(UrlHelper url, string returnUrl)
{
if (!String.IsNullOrWhiteSpace(returnUrl)
&& url.IsLocalUrl(returnUrl)
&& returnUrl.Length > 1
&& returnUrl.StartsWith("/", StringComparison.Ordinal)
&& !returnUrl.StartsWith("//", StringComparison.Ordinal)
&& !returnUrl.StartsWith("/\\", StringComparison.Ordinal))
{
return returnUrl;
}
return url.Home();
}
示例3: redirect
///////////////////////////////////////////////////////////////////////
public static void redirect(HttpRequest Request, HttpResponse Response)
{
// redirect to the page the user was going to or start off with bugs.aspx
string url = Request.QueryString["url"];
string qs = Request.QueryString["qs"];
UrlHelper urlHelper = new UrlHelper(Request.RequestContext);
if (String.IsNullOrEmpty(url) || !urlHelper.IsLocalUrl(url))
{
string mobile = Request["mobile"];
if (String.IsNullOrEmpty(mobile))
{
Response.Redirect("bugs.aspx");
}
else {
Response.Redirect("mbugs.aspx");
}
}
else
{
Response.Redirect(remove_line_breaks(url) + "?" + remove_line_breaks(HttpUtility.UrlDecode(qs)));
}
}
示例4: IsSafe
public bool IsSafe(string url)
{
UrlHelper helper = new UrlHelper(context);
return helper.IsLocalUrl(url) && url.Length > 1 && url.StartsWith("/") && !url.StartsWith("//") && !url.StartsWith("/\\");
}