在一个地方进行重定向的最佳方法是什么ActionFilterAttribute?我有一个ActionFilterAttribute调用IsAuthenticatedAttributeFilter并检查会话变量的值.如果变量为false,我希望应用程序重定向到登录页面.我更喜欢使用路由名称SystemLogin重定向,但此时任何重定向方法都可以.
我正在编写一个授权过滤器属性,因为我无法弄清楚如何将当前url作为字符串获取,所以我可以将它作为参数传递给LogOn操作.目标是,如果用户成功登录,他们将被重定向到他们最初尝试访问的页面.
public override void OnAuthorization(AuthorizeContext filterContext)
{
base.OnAuthorization(filterContext);
... my auth code ...
bool isAuth ;
... my auth code ...
if(!isAuth)
{
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary {
{ "Area", "" },
{ "Controller", "Account" },
{ "Action", "LogOn" },
{ "RedirectUrl", "/Url/String/For/Currnt/Request" } // how do I get this?
}
);
}
}
Run Code Online (Sandbox Code Playgroud)
如何从当前请求中获取完整的字符串Url?
url asp.net-mvc authorization action-filter actionfilterattribute
更新:重写简洁......
使用ASP.NET MVC项目,是否可以将web.config重写规则优先于MVC的RegisterRoutes()调用,或者IgnoreRoute只针对特定域调用?
我有一个MVC应用程序接受多个域(mydomain.com和otherdomain.com)上的流量,应用程序根据请求的主机(即它是多租户)提供不同的内容.
我在web.config中配置了URL重写(反向代理),它只应用于特定主机:
<rule name="Proxy" stopProcessing="true">
<match url="proxy/(.*)" />
<action type="Rewrite" url="http://proxydomain.com/{R:1}" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(mydomain\.com|www\.mydomain\.com)$" />
</conditions>
<serverVariables>
<set name="HTTP_X_UNPROXIED_URL" value="http://proxydomain.com/{R:1}" />
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
<set name="HTTP_X_ORIGINAL_HOST" value="{HTTP_HOST}" />
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
Run Code Online (Sandbox Code Playgroud)
但是,MVC应用程序似乎只会尊重web.config配置的路由,如果它们从应用程序的RegisterRoutes()方法中被忽略:
routes.IgnoreRoute("proxy");
Run Code Online (Sandbox Code Playgroud)
然而,遗憾的是,将忽略应用于两个域.建议非常感谢...
我正在尝试创建一个全能路由来跟踪联盟字符串何时在URL中.联盟代码由a x后跟a 标记int,并且仅出现在URL的末尾(但在查询字符串之前).
我的想法是,我将提取联盟会员ID,进行一些日志记录,然后在没有联盟会员ID的情况下对同一请求执行301.
例如:
http://www.domain.com/x32
http://www.domain.com/x32/
http://www.domain.com/path/to/something/x32
http://www.domain.com/x32?query=string
http://www.domain.com/x32/?query=string
http://www.domain.com/path/to/something/x32?query=string
http://www.domain.com/path/to/something/x32/?query=string
Run Code Online (Sandbox Code Playgroud)
我有这条路
routes.Add(new Route("{url}/x{affiliateExternalId}", new MvcRouteHandler())
{
Defaults = new RouteValueDictionary(
new { controller = "Home", action = "LogCookieAndRedirect" }
),
Constraints = new RouteValueDictionary(new { affiliateExternalId = @"\d{1,6}" })
});
Run Code Online (Sandbox Code Playgroud)
哪个只匹配
http://www.domain.com/path/x32
http://www.domain.com/path/x32/
Run Code Online (Sandbox Code Playgroud)
我需要做什么来匹配所有内容并将查询字符串传递给控制器?有一个*我怀疑我应该使用的操作员,但是我不能让它做我需要的.
asp.net-mvc ×4
asp.net ×1
c# ×1
iis ×1
orchardcms ×1
redirect ×1
routes ×1
routing ×1
url ×1
url-routing ×1