Asp.net mvc 4 使用ViewData将请求的URL发送到超链接的视图,URL会截断参数
我使用的过滤器在用户到达网站时检查其浏览器/版本。如果他们使用不受支持的浏览器,我会将他们想要访问的URL保存到名为“RequestedURL”的ViewData中,并重定向到一个视图,告诉他们他们的浏览器是旧的。此视图允许用户通过单击链接继续操作。此链接的URL由过滤器中设置的ViewData属性“RequestedUrl”填充 过滤器:Asp.net mvc 4 使用ViewData将请求的URL发送到超链接的视图,URL会截断参数,asp.net-mvc-4,viewdata,custom-action-filter,Asp.net Mvc 4,Viewdata,Custom Action Filter,我使用的过滤器在用户到达网站时检查其浏览器/版本。如果他们使用不受支持的浏览器,我会将他们想要访问的URL保存到名为“RequestedURL”的ViewData中,并重定向到一个视图,告诉他们他们的浏览器是旧的。此视图允许用户通过单击链接继续操作。此链接的URL由过滤器中设置的ViewData属性“RequestedUrl”填充 过滤器: /// <summary> /// If the user has a browser we don't support, this will
/// <summary>
/// If the user has a browser we don't support, this will present them with a page that tells them they have an old browser. This check is done only when they first visit the site. A cookie also prevents unnecessary future checks, so this won't slow the app down.
/// </summary>
public class WarnAboutUnsupportedBrowserAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var request = filterContext.HttpContext.Request;
//this will be true when it's their first visit to the site (will happen again if they clear cookies)
if (request.UrlReferrer == null && request.Cookies["browserChecked"] == null)
{
//give old IE users a warning the first time
if ((request.Browser.Browser.Trim().ToUpperInvariant().Equals("IE") && request.Browser.MajorVersion <= 7) ||
(request.Browser.Browser.Trim().ToUpperInvariant().Equals("Chrome") && request.Browser.MajorVersion <= 22) ||
(request.Browser.Browser.Trim().ToUpperInvariant().Equals("Mozilla") && request.Browser.MajorVersion <= 16) ||
(request.Browser.Browser.Trim().ToUpperInvariant().Equals("Safari") && request.Browser.MajorVersion <= 4))
{
filterContext.Controller.ViewData["RequestedUrl"] = request.Url.ToString();
filterContext.Result = new ViewResult { ViewName = "UnsupportedBrowserWarning" };
}
filterContext.HttpContext.Response.AppendCookie(new HttpCookie("browserChecked", "true"));
}
}
}
如果用户输入的Url为“./Controller/Foo/providerkey”,则在视图中填充的Url为“Controller/Foo”,其中缺少访问页面所需的参数
如何确保视图中的URL是用户最初输入的整个URL?我在这里没有看到任何会导致删除参数的内容。如果删除筛选器,是否会填充参数?@AntP如果不使用筛选器,则永远不会触及带有ViewData RequestedUrl的视图,因此是的,参数位于未触及的URL中,并且控制器方法正常工作。
<a href="@ViewData["RequestedUrl"] ">Thanks for letting me know.</a>
[WarnAboutUnsupportedBrowser]
public ActionResult Index(string providerkey)