.NET的MVC - 通过SSL重写URL的某些+ URL的? [英] .NET-MVC - Rewrite URL's + certain URL's through SSL?
本文介绍了.NET的MVC - 通过SSL重写URL的某些+ URL的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Web服务器运行IIS 6,.NET MVC使用一个域名。该网站将使用URL重写产生类似的网址:
I have a webserver running IIS 6, .NET MVC with a single domainname. The site uses URL rewriting to produce URLs like:
domain.com/controller/action
domain.com/controller/action
我想迫使一(1)控制器使用 SSL
(其他人应无SSL工作)。 我应该如何实现这一点?
I would like to force one (1) controller to use SSL
(others should work without SSL). How should I implement this?
推荐答案
装饰需要SSL与的 RequireHttpsAttribute 。
[RequireHttps]
public class SecureController : Controller
{
...
}
虽然,你可能preFER如果您使用卡西尼调试忽略此为本地请求的定制版本。
Although, you may prefer a custom version that ignores this for requests from localhost if you are using Cassini for debugging.
[AttributeUsage( AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false )]
public class RemoteRedirectToHttpsAttribute : RequireHttpsAttribute
{
public override void OnAuthorization( AuthorizationContext filterContext )
{
if (filterContext == null)
{
throw new ArgumentNullException( "filterContext" );
}
if (filterContext.HttpContext != null && (filterContext.HttpContext.Request.IsLocal || filterContext.HttpContext.Request.IsSecureConnection))
{
return;
}
filterContext.Result = new RedirectResult( filterContext.HttpContext.Request.Url.ToString().Replace( "http:", "https:" ) );
}
}
这篇关于.NET的MVC - 通过SSL重写URL的某些+ URL的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文