0
У меня есть следующий код в моих методах действий: -«проливает новый HttpException» не будет ничего возвращать ошибку
public ActionResult ManageCustomerVLANs(string customerName)
{
if (!repository.IsCustomerExsists(customerName))
{
throw new HttpException(404, "Your error message");//RedirectTo NoFoundPage
}
И я определил следующее в моем web.config, чтобы справиться с любым кодом 404 HTTP: -
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="NoCache" noStore="true" duration="0" varyByParam="*"/>
</outputCacheProfiles>
</outputCacheSettings>
</caching>
<!--<customErrors mode="RemoteOnly"/>-->
<customErrors mode="RemoteOnly">
<error statusCode="404" redirect="~/Home/" />
</customErrors>
Но в настоящее время, если метод действия возврата “throw new HttpException”
, ничего фактически не возвращается, и выполнение будет продолжаться и после этого “throe new HttpException”
. так может кто-нибудь советовать, как я могу вернуть http 404?
лучше, чтобы вернуть 'HttpStatusCodeResult' вместо, как показано здесь http://stackoverflow.com/questions/17148554/asp-net-mvc-4-throw-httpexception-vs-return-httpstatuscoderesult?rq=1 – Amitd
или вы можете попробовать, как показано здесь http://stackoverflow.com/questions/13905164/how-to-make-custom-error-pages-work-in-asp-net-mvc-4?rq=1 – Amitd