我在ASP.NET MVC Filter文件夹/命名空间中添加了一个新的Filter类。之前还有一个Visual Studio允许我通过Filter.blahblahblah找到它,但新的一个根本不会被引用...我不明白。我是否需要做任何其他事情才能找到新的过滤器?
using System;
using System.Web;
using System.Web.Mvc;
namespace Filters
{
public class RequiresSSL : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpRequestBase req = filterContext.HttpContext.Request;
HttpResponseBase res = filterContext.HttpContext.Response;
//Check if we're secure or not and if we're on the local box
if (!req.IsSecureConnection && !req.IsLocal)
{
var builder = new UriBuilder(req.Url)
{
Scheme = Uri.UriSchemeHttps,
Port = 443
};
res.Redirect(builder.Uri.ToString());
}
base.OnActionExecuting(filterContext);
}
}
}
答案 0 :(得分:2)
尝试命名为RequiresSSLAttribute。使用标准约定,编译器将[RequiresSSL]扩展为RequiresSSLAttribute。