httpexception

Rendering a view to a string in MVC, then redirecting — workarounds?

心已入冬 提交于 2019-12-01 06:41:44
I can't render a view to a string and then redirect, despite this answer from Feb (after version 1.0, I think) that claims it's possible. I thought I was doing something wrong, and then I read this answer from Haack in July that claims it's not possible. If somebody has it working and can help me get it working, that's great (and I'll post code, errors). However, I'm now at the point of needing workarounds. There are a few, but nothing ideal. Has anybody solved this, or have any comments on my ideas? This is to render email. While I can surely send the email outside of the web request (store

Rendering a view to a string in MVC, then redirecting — workarounds?

此生再无相见时 提交于 2019-12-01 05:01:36
问题 I can't render a view to a string and then redirect, despite this answer from Feb (after version 1.0, I think) that claims it's possible. I thought I was doing something wrong, and then I read this answer from Haack in July that claims it's not possible. If somebody has it working and can help me get it working, that's great (and I'll post code, errors). However, I'm now at the point of needing workarounds. There are a few, but nothing ideal. Has anybody solved this, or have any comments on

Throwing an HttpException always sends back HTTP 500 error?

前提是你 提交于 2019-11-30 13:13:12
问题 I'm trying to throw an HTTP 403 error code back at the client. I've read that HttpException is the cleanest way to accomplish this, but it's not working for me. I throw the exception from within a page like this: throw new HttpException(403,"You must be logged in to access this resource."); However, this will only give a standard ASP.Net stack trace(with 500 error) when CustomErrors is off. If CustomErrors is on, then this will not redirect to the page I have setup to be displayed when a 403

BinaryWrite exception “OutputStream is not available when a custom TextWriter is used” in MVC 2 ASP.NET 4

别说谁变了你拦得住时间么 提交于 2019-11-30 11:18:51
I have a view rendering a stream using the response BinaryWrite method. This all worked fine under ASP.NET 4 using the Beta 2 but throws this exception in the RC release: "HttpException" , "OutputStream is not available when a custom TextWriter is used." <%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage" %> <%@ Import Namespace="System.IO" %> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (ViewData["Error"] == null) { Response.Buffer = true; Response.Clear(); Response.ContentType = ViewData["DocType"] as string; Response.AddHeader("content

Diagnosing “Request timed out” HttpExceptions

梦想的初衷 提交于 2019-11-30 10:47:24
问题 Here on StackOverflow, we're seeing a few "Request timed out" exceptions every day. The facts: Request timeout is the default 90 seconds Occurs only on POSTs Data posted is text, usually small (< 1KB), but can range to a few KB No Form data is captured in server variables Client UAs are diverse: IE5.5 - 7, Firefox 3.0.5, iPhone, Chrome Client locations are diverse: UK, France, USA - NC, OH, NE, IN We've tested a server-based timeout (i.e. using Thread.Sleep) and all form variables are

Diagnosing “Request timed out” HttpExceptions

馋奶兔 提交于 2019-11-29 21:27:57
Here on StackOverflow, we're seeing a few "Request timed out" exceptions every day. The facts: Request timeout is the default 90 seconds Occurs only on POSTs Data posted is text, usually small (< 1KB), but can range to a few KB No Form data is captured in server variables Client UAs are diverse: IE5.5 - 7, Firefox 3.0.5, iPhone, Chrome Client locations are diverse: UK, France, USA - NC, OH, NE, IN We've tested a server-based timeout (i.e. using Thread.Sleep) and all form variables are correctly captured in the exception log - this leads us to believe the client is having issues sending the

How do I get StatusCode from HttpRequestException?

不问归期 提交于 2019-11-29 00:48:56
I'm probably missing something obvious here. I'm using HttpClient which throws HttpRequestException that contains StatusCode in the Message string. How can I access that StatusCode ? Edit : More info, I wrote this question in rush. I'm using HttpClient to access another API within my WebApi project. Yes, I know why I'm calling EnsureSuccessStatusCode() . I want to propagate some errors downstream such as 404 and 403. All I wanted was to consistently transform HttpRequestException into HttpResponseException using custom ExceptionFilterAttribute . Unfortunately, HttpRequestException does not

ASP.Net debug directory monitoring HttpException

你离开我真会死。 提交于 2019-11-28 01:51:54
When I start my ASP.Net 4.0 web app in debug mode, I'm getting the following exception: System.Web.HttpException occurred Message=Invalid file name for file monitoring: 'C:\src\main-232\src\ZNode\Znode_MultiFront\Web\Controls\Cat5\Navigation'. Common reasons for failure include: - The filename is not a valid Win32 file name. - The filename is not an absolute path. - The filename contains wildcard characters. - The file specified is a directory. - Access denied. Source=System.Web ErrorCode=-2147024809 WebEventCode=0 StackTrace: at System.Web.DirectoryMonitor.AddFileMonitor(String file)

HttpContext throws HttpException

北城余情 提交于 2019-11-27 21:16:04
I have written a custom http handler. I have done this by writing a class which implements the IHttphandler. Inside that class I have code like this, context.Response.Clear(); context.Response.ClearHeaders(); context.Response.AddHeader("Content-Disposition", "attachment;filename=" + attachmentFileName); context.Response.AddHeader("Content-Length", new FileInfo(downloadFile).Length.ToString()); context.Response.ContentType = GetMimeType(attachmentFileName); context.Response.TransmitFile(downloadFile); context.Response.Flush(); context.Response.Close(); Occasionally I receive an error like this,

ASP.NET Core equivalent of ASP.NET MVC 5's HttpException

亡梦爱人 提交于 2019-11-27 11:32:39
In ASP.NET MVC 5 you could throw a HttpException with a HTTP code and this would set the response like so: throw new HttpException((int)HttpStatusCode.BadRequest, "Bad Request."); HttpException does not exist in ASP.NET Core. What is the equivalent code? I implemented my own HttpException and supporting middleware which catches all HttpException 's and turns them into the corresponding error response. A short extract can be seen below: You can use the Boilerplate.AspNetCore Nuget package or you can view the full source code on the following ASP.NET MVC Boilerplate GitHub project, or create a