httpexception

Server cannot modify cookies after HTTP headers have been sent

微笑、不失礼 提交于 2020-01-13 15:03:42
问题 I am creating a web application in C#. When my page loads I fire an asynchronous thread to process some data. Part of this processing is the updating of a cookie. However when I save the cookie to the response by System.Web.HttpContext.Current.Response.Cookies.Add(cookie) , I get the following exception: HttpException: Server cannot modify cookies after HTTP headers have been sent. Any way I can work around or fix this? 回答1: Unless you have a very good reason to, you shouldn't be spinning up

When HttpStatusCodeException exception raised?

时间秒杀一切 提交于 2019-12-20 07:56:38
问题 when i use below code , what is the case to get HttpStatusCodeException exception . ResponseEntity<Object> response = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, entity, Object.class); Please can anyone help out ???????? 回答1: HTTP Status Codes are responses from the server, therefore if you have control of the server then you could make it return whichever errors you want. If you don't have control of the server then you could try sending bad/invalid requests so

When HttpStatusCodeException exception raised?

徘徊边缘 提交于 2019-12-20 07:54:04
问题 when i use below code , what is the case to get HttpStatusCodeException exception . ResponseEntity<Object> response = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, entity, Object.class); Please can anyone help out ???????? 回答1: HTTP Status Codes are responses from the server, therefore if you have control of the server then you could make it return whichever errors you want. If you don't have control of the server then you could try sending bad/invalid requests so

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

ぐ巨炮叔叔 提交于 2019-12-18 14:14:54
问题 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;

How do I get StatusCode from HttpRequestException?

旧巷老猫 提交于 2019-12-17 18:45:03
问题 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

Catching “Maximum request length exceeded”

痴心易碎 提交于 2019-12-17 01:44:07
问题 I'm writing an upload function, and have problems catching "System.Web.HttpException: Maximum request length exceeded" with files larger than the specified max size in httpRuntime in web.config (max size set to 5120). I'm using a simple <input> for the file. The problem is that the exception is thrown before the upload button's click-event, and the exception happens before my code is run. So how do I catch and handle the exception? EDIT: The exception is thrown instantly, so I'm pretty sure

Why do I get an HttpException from VirtualPathUtility ToAbsolute with some paths?

拜拜、爱过 提交于 2019-12-10 16:24:27
问题 I'm trying to use VirtualPathUtility.ToAbsolute to resolve app-relative paths, such as ~/MyPage.aspx , to application-absolute paths, such as /MySite/MyApp/MyPage.aspx . However, with some paths, I receive an HttpException saying that my path is "not a valid virtual path". Examples: // This works: var abs1 = VirtualPathUtility.ToAbsolute("~/MyPage.aspx#anchor"); // This errors: var abs2 = VirtualPathUtility.ToAbsolute("~/MyPage.aspx?key=value"); What's going on? 回答1: Because you're using .NET

Render view to string followed by redirect results in exception

夙愿已清 提交于 2019-12-09 23:39:10
问题 So here's the issue: I'm building e-mails to be sent by my application by rendering full view pages to strings and sending them. This works without any problem so long as I'm not redirecting to another URL on the site afterwards. Whenever I try, I get "System.Web.HttpException: Cannot redirect after HTTP headers have been sent." I believe the problem comes from the fact I'm reusing the context from the controller action where the call for creating the e-mail comes from. More specifically, the

Stop exception from being thrown for non-existent controller

拈花ヽ惹草 提交于 2019-12-09 09:32:17
问题 Ok, so I am stumped on this issue. I have seen a lot of things that are supposed to resolve this issue, but I am not getting a resolution that can fulfill my requirements. I am using ELMAH to log exceptions and am getting this exception when either a URL with invalid controller or proper controller and invalid action. System.Web.HttpException: The controller for path '/BadController' was not found or does not implement IController. at System.Web.Mvc.DefaultControllerFactory

How to catch a specific HttpException (#0x80072746) in an IHttpHandler

旧街凉风 提交于 2019-12-07 13:03:05
问题 It appears that this HttpException (0x80072746 - The remote host closed the connection) can be thrown if, for example, the user closes the window whilst we are transmitting a file. Even if we send the files in smaller blocks and check the client is still connected, the exception can still occur. We want to be able to catch this specific exception, to ignore it. The ErrorCode provided in the HttpException is an Int32 - too small to hold 0x80072746, so where do we find this number? 回答1: Int32