我在web.config中设置了customErrors
<customErrors mode="On" defaultRedirect="/Error/GeneralError">
<error statusCode="404" redirect="/Error/NotFound"/>
</customErrors>
Run Code Online (Sandbox Code Playgroud)
这在当地工作正常.404会抛出404.在共享主机上,它会抛出标准服务器404页面,除非我专门设置404指向/ Error/NotFound.没关系.现在它将显示自定义404页面,但响应状态代码为200.所以如果我尝试抛出Response.StatusCode = 404; 在我在ErrorController中的NotFound操作中,如下所示:
public class ErrorController : Controller
{
public ActionResult NotFound()
{
Response.StatusCode = 404;
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
服务器抛出状态代码500内部服务器错误,但我的GeneralError页面没有显示,只是一个没有源的空白页面.
我尝试了很多不同的组合,但我似乎无法找到如何让它显示我的自定义404页面以及404响应.
有任何想法吗?
我有一个MVC应用程序,使用[授权]来保护私人位.当我选择SignOut()URL时,它会告诉我,但如果我点击浏览器上的后退按钮,它就会转到安全页面,甚至让我使用该表单.行动发生,然后它显示我已退出.问题是它执行安全操作(在我的数据库中插入一行).然后我可以再次使用后退按钮并全部完成.如果我在注销后使用后退按钮并点击浏览器刷新它确实显示我已注销并拒绝访问安全页面.
我错过了重要的事吗?看起来这可能是一个非常大的安全问题.
public ActionResult LogOff(string ReturnUrl)
{
FormsAuth.SignOut();
if (!String.IsNullOrEmpty(ReturnUrl))
{
return Redirect(ReturnUrl);
}
else
{
return RedirectToAction("Index", "Page");
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用以下 HttpModule 来阻止几个不断尝试向我的联系表单发送垃圾邮件的 IP。我没有收到垃圾邮件,因为它们触发了 System.Web.HttpRequestValidationException,但我确实在电子邮件收件箱中收到了异常报告。虽然没那么烦人,但也差不多了。
我最终想要针对数据库中的 IP 列表进行测试,或者可能实现 HttpBL api 来针对已知的黑名单 IP 进行测试,但对每个请求执行此操作似乎有些过分了。不管怎样,无论是使用数据库中的 IP 还是在每个页面请求时向外部黑名单发出请求,似乎都是不必要的。你能给我指出检查一次的方向吗?如果IP第一次通过测试就停止检查?
using System;
using System.Web;
namespace DomainModel.Services
{
public class BlockIPModule : IHttpModule
{
public void Dispose() {}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(Application_BeginRequest);
}
private void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
string currentIP = context.Request.UserHostAddress;
if (!IsIpValid(currentIP))
{
context.Response.StatusCode = 403;
}
}
private bool IsIpValid(string checkIP)
{
return (checkIP != "213.5.70.205" && checkIP != "188.92.75.82");
}
} …Run Code Online (Sandbox Code Playgroud) 它不会经常发生,但我会不时通过电子邮件向我发送一份异常报告,指向这段代码.我想知道你是否看到以下代码有任何问题.我不能让它在本地失败,并且使用断点跟踪数据总是一步一步地给出正确的结果.
namespace DomainModel.Concrete
{
public class ConfigRepository : IConfigRepository
{
static mvCmsContext context { get; set; }
public ConfigRepository() { context = new mvCmsContext(); }
private static Func<mvCmsContext, string, Configuration> _byName =
CompiledQuery.Compile((mvCmsContext context, string configName) =>
(from c in context.Configs
where c.configName == configName
select c).SingleOrDefault());
static public Configuration ByName(string configName)
{
var result = (Configuration)HttpContext.Current.Cache.Get(configName);
if (result == null)
{
using (new mvCmsContext())
{
HttpContext.Current.Cache.Insert(configName, _byName(context, configName));
result = (Configuration)HttpContext.Current.Cache.Get(configName);
}
}
return result;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是调用该方法的服务: …