C# - Does Custom Errors Override The Actual HTTP Response Code

Mar 28, 2011

If I were to specify a page for redirect using the ASP.NET Custom Errors feature, would my application still spit out the HTTP status code for that particular error?

For example if had a line in my web.config that had all Internal Server Errors redirect to Errors/500.aspx and then I encountered a 500 error, I would then be redirected to my custom Errors/500.aspx page. Will my application still respond with a HTTP 500 at any point in this exchange?

View 1 Replies


Similar Messages:

Custom HTTP Response C# And Ajax?

Apr 4, 2011

I'm trying to query a database that contains information about a "ticket" using jQuery's .ajax() method.

$.ajax({
type: 'GET',
url: 'Preview.ashx',
data: 'ticketID=' + ticketID,
success: function (data) {
// 'data' should be a row from the database, so it should be like an
// array that contains each column of the row
// do stuff with this data
}
});
... so that all works fine. I'm having trouble with the data variable. On the server side, I do...
// get the ticket ID from the POST parameter
int ticketID = context.Request["ticketID"] != null ? Convert.ToInt32(context.Request["ticketID"]) : -1;
if (ticketID >= 0) {
// grab the data from the database, getInfo() will retrieve the row
// in the DB that corresponds to the ticket ID given, returning an
// ArrayList with all of the information
ArrayList theTicket = getInfo(context, ticketID);
// now, I need to somehow return this information so that I could deal with it
// in the 'success' callback function above
return;
} else {
// something went wrong with the 'newTicket' POST parameter
context.Response.ContentType = "text/plain";
context.Response.Write("Error with 'ticketID' POST parameter.
");
return;
}
return;

I've debugged this enough to be sure that the ArrayList contains the correct information. Now I just need to return it. How would I do this? How would I return the data in the ArrayList? Is it possible to structure the response so that I could do data.ID, data.otherColumnName, etc... in the callback function to access the different fields?

View 3 Replies

Response - Get Custom Http Header?

May 14, 2010

I have an asp.net appliction on the one server. There I've added code on server-side in Page_Load:

Response.AddHeader("key", "password-key-from-hotel");

On the client side I have a form:
<form ... action="www.link-to-another-domaint" >
<input type="hidden" id="asd" value="fgh" >
....
</form>
<script type="text/javascript">
document.forms[0].submit();
</script>

Then on the other domain - there is also my other application - I'm trying to get the hedaer "key" by this code:

Request.Headers["key"].ToString();

But there is no such header. Is there is a desicion? Where is my mistake?

View 2 Replies

Http - Writing A Custom NTLM Challenge/response In C#?

Jan 18, 2011

I know that you can enable NTLM authentication in an ASP.Net app using:

<authentication mode="Windows" />

However - I need to handle Forms, HTTP and other custom authentications in the same app, so ASP.Net's limited built-in support is no use.

The NTLM handshake should be fairly simple:

Request - [unauthenticated - no user info passed]
Response - 401 Unauthorized
WWW-Authenticate: NTLM
Request - Authorization: NTLM <base64-encoded type-1-message>

[code]...

I need to parse type-1 and type-3 messages and generate a type-2 message.

The structure for those messages is well documented but fairly complex - it seems very messy to write my own message generators and parsers. I think the methods to read and write these messages should already be in .Net, but I haven't been able to find them.

View 1 Replies

Re-write A String And Convert Http Text Into Actual Web Links?

Nov 27, 2010

In my code below, I'm trying to re-write a string and convert and http text into actual web links.

It doesn't seem to be working and I think the problem may be that I'm rewriting the string and inserting another http string into the original string which then causes problems with the loop.

[Code]....

View 8 Replies

Application Hosted On IIS7 That Is Ignoring Custom Errors And Falls Back To IIS Errors?

Jul 2, 2010

I have a C# web forms ASP.NET 4.0 web application that uses Routing for URLs for some reason custom errors defined in the system.web section of my web.config is entirely ignored and it will fall back the IIS errors.

This gets entirely ignored

[code]....

This would be a minor inconvenience except that by the fact it falls back to IIS native instead of my application it completely circumvents Elmah logging my 404 exceptions correctly.

View 3 Replies

Send Fodder Bytes Until Actual Response Data Is Ready?

Jan 19, 2010

I need to serve MP3 content that is generated dynamically during the request. My clients (podcatchers I can't configure) are timing out before I'm able to generate the first byte of the response data.

Is there a way to send fodder/throwAway data while I'm generating the real data, to prevent/avoid the timeout, but in a way that allows me to instruct the client to ignore/discard the fodder data once I'm ready to start sending the "real" data?

View 2 Replies

Web Forms :: Override Custom Method In Custom Control?

Feb 17, 2011

I have created a custom control as can be seen below. this custom control will be used by alot of web form. The question is how to override CheckAllData method in each webform, so i can write my own checking in each webform.

[Code]....

View 5 Replies

Debug Http 500 Errors

Jun 9, 2010

I've developed a fairly simple web service which receives an xml string, validates it and passes it on to our internal database. This has been written to enable one of our clients to send us idocs from their SAP system. The trouble is that, although the web service works fine from a .net program, over the internet, the client's SAP system can't access it. They either get just an http 200 back (rather than the status code that the web service should supply) or they get http 500 'Internal Server Error'. I was wondering if anyone else has had issue's with ASP.NET web services from non 1qs`asp.net applications, or whether anyone can give me any advice on debugging http 500 errors.

View 4 Replies

Web Forms :: Handle Custom Errors Using Custom Error Page?

May 7, 2015

I want put custom error page in my website so I wrote below code in web.config

<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="error-404.aspx" responseMode="ExecuteURL" />
</httpErrors>

is it correct?

or I should put other code?

View 1 Replies

How To Handle 403.9 HTTP Errors In The Web.config File

Nov 23, 2010

Do anyone of you know how to handle XXX.X IIS HTTP errors in a web.config file? I tried doing the following:

<customErrors mode="On" defaultRedirect="error.aspx">
<error statusCode="403" redirect="error403.aspx" />
<!--NOTE: The following does not work-->
<error statusCode="403.9" redirect="error403.9.aspx" />
<!--ENDNOTE-->
<error statusCode="404" redirect="error404.aspx" />
</customErrors>

But obviously that didn't worked, because the web.config file expects an integer as the statusCode value.
CONTEXT: WinServer 2003 - ASP.NET 3.5

View 1 Replies

App_offline.htm Throwing HTTP 500 Errors On Production Box / How To Fix It

Feb 8, 2011

I have created an app_offline.htm file for an ASP.NET MVC2 application running on IIS7 / Win2008 64-bit, and ensured that it's over 512 bytes (it's 2KB right now). On my dev box running Visual Studio 2010, it works like a charm, but when I put it on the production box, all I get is the generic HTTP 500 error saying "The page cannot be displayed because an internal server error has occurred."

What's especially strange is that I don't get anything logged in the application event log, nor does ELMAH pick anything up. I've disabled custom errors, put FormsAuthentication location exceptions for the file, ensured I'm not referencing any other files (images, etc.), but nothing fixes it.

View 1 Replies

Getting Redirection To Custom Error Page Using Custom Errors

Mar 24, 2010

Here's my Application_OnError event sink in global.asax.vb:

Sub Application_OnError(ByVal sender As Object, ByVal e As EventArgs)
Dim innerMostException As Exception = getInnerMostException(Me.Context.Error)
If TypeOf innerMostException Is AccessDeniedException Then
Security.LogAccessDeniedOccurrence(DirectCast(innerMostException, AccessDeniedException))
Dim fourOhThree As Integer = DirectCast(HttpStatusCode.Forbidden, Integer)
Throw New HttpException(fourOhThree, innerMostException.Message, innerMostException)
End If
End Sub

You'll see that if we've got an innermost Exception of type AccessDeniedException we throw a new HTTPExcpetion with a status code of 403 AKA 'forbidden'

Here's the relevant web.config entry:

<customErrors defaultRedirect="~/Application/ServerError.aspx" mode="On">
<error statusCode="403" redirect="~/Secure/AccessDenied.aspx" />
</customErrors>

So what we're expecting is a redirect to the AccessDenied.aspx page. What we get is a redirect to the ServerError.aspx page.

We've also tried this:

Sub Application_OnError(ByVal sender As Object, ByVal e As EventArgs)
Dim innerMostException As Exception = getInnerMostException(Me.Context.Error)
If TypeOf innerMostException Is AccessDeniedException Then
Security.LogAccessDeniedOccurrence(DirectCast(innerMostException, AccessDeniedException))
Context.Response.StatusCode = DirectCast(HttpStatusCode.Forbidden, Integer)
End If
End Sub

Which unsuprisingly doesn't work either.

View 1 Replies

Web Forms :: Code Removing A Actual Sitemapnode

Feb 14, 2011

I am developing an ASP.NET web page with C#. I have a sitemap document but I want to hide certain nodes based on the user's credentials. However, I am having problems with my code removing the actual node. Visual Studio runs the program with no errors. However, the node is still there. Below is the code I have developed for this. The node changes text to "it worked" as I hope written. However, it will not remove itself. I can get the item to be disabled, change enablement, but I need to hide it completely from the viewers view - not the document.

[Code]....

View 4 Replies

MVC :: Switching Tutorial Does Not Change The Actual Code Text Examples

Feb 26, 2011

The following link: [URL]javascript has a link on the right-hand-side to switch code from C# to VB, but the actual example text does not change when the selection is chosen. Can someone tell me if this tutorial is exclusively for C#, or can it be built in VB as well?

View 2 Replies

C# - In EF4.1 Code First - Override ConnectionString Name In Web.configuration?

Mar 23, 2011

I'm creating a multi-tenant Asp.Net MVC 3 Web app, and using EF4.1 code first for the db model.For development I'm happy to use SqlServerCE in App_Data, and for production this will move to Sql Server 2008.

Say my context is called "MyModels", by default code-first looks for a connection string called "MyModels" in Web.config. This can be told to use a file in App_Data or changed to access a database in SQL2008. All fine so far.

But because of multi-tenancy, I'd like the SqlServerCE filename to match the unique id of the tenant (so App_Data would have "client_x.sdf", "client_y.sdf"; Sql Server 2008 would have separate databases). I can't work out how to direct to these different databases.

I've tried MyModels inheriting from DbContext and supplying a connection string (using a 'placeholder' conn string in Web.config and replacing "{clientId}" with the unique id), and I've also tried setting the connection string in the MyModels constructor:

base.Database.Connection.ConnectionString = xxx;


but this never seems to work. I always get the following error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

( it's not yet 'configured' to use SqlServerCE, and so is trying to connect to Sql Server)

Tracing the code, Database.Connection.ConnectionString hasn't been read from Web.config at this point, so I can't search and replace that, and, possibly, it's getting overwritten by the 'placeholder' conn string later in the pipeline.I reckon this must be quite straightforward and I just can't find the 'hook'.

View 2 Replies

Web Forms :: Override UserControl Function From .net Page Code Behind?

Jan 11, 2011

I want to ask if I can overried a function the presents at Usercontrol that I created that Mean

I can update the function if there a need for that {Virtual,.....}

I want to override that function from the asp.net codebehind that hold that user control.

View 3 Replies

C# - MP3 Download In An HTTP Response?

Jun 9, 2010

I've a question about something I'm searching for,for too long! We've build an application from which an admin upload songs into a database. Then user can bought songs and download it individualy. The problem is that when user download MP3 songs with the code below, it works great in Firefox and Chrome but not in IE8 simply because WMP trying to open the songs and it just don't get it instead of having a "Save as" dialog? Any issue on HOW can i force to have the "Save As" diaglog? Note that I have not MP3 physicaly on server it's in database. So I can't direct link to song ...

Here's my code :

// Remove "specials chars"
foreach (char aChar in @"/:*?""<>| ") {
if (aChar == ' ') {
songNameAndExt = songNameAndExt.Replace(' ', '_');
} else {
songNameAndExt = songNameAndExt.Replace(aChar.ToString(), string.Empty);
}
}
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.Headers.Add("Content-Disposition", string.Format("filename={0}", songNameAndExt));
HttpContext.Current.Response.OutputStream.Write(songData, 0, songLength);

View 1 Replies

HTTP Response And Request In Binary

Feb 21, 2010

I need to I can make the web request to a webservice which take a XML argument. And is expected to return a Binary response. I am able to make the request but while recieving the response back I am unable to get the response in binary. When I read the response
using streamreader see the header and some attached "HEBRISH" words probably binary but unable to sepreate it out. Please help in seprating out the binary the response data.

View 1 Replies

Web Forms :: Get Response Value - From Http Post

Mar 23, 2011

What wrong with this code?

[Code]....

I would like the numeric values of the enum of Response.StatisCode

View 1 Replies

Suppressing HTTP 500 Response Codes

Feb 10, 2010

I've had a bit of feedback from some threat and vulnerability folks relating to websites returning HTTP 500 response codes. Essentially the advice is that all possible measures must be taken to avoid the server throwing a 500 (i.e. extensive form input validation) which is fine. However, the advice also suggested that attempts to compromise security by means such as inserting a tag into a random query string causing ASP.NET request validation to fire or manipulating viewstate also should not return an HTTP 500. Obviously the native framework behaviour is to interpret the request and possibly throw to a custom error page but even this will return a 500 response code.

So I'm after some thoughts on how to approach this. Is there any way to configure the app at either the .NET level or IIS level to return an HTTP 200 when a 500 is raised? Or does this become a coding exercise at global.asax level in one of the application events? Are there other consequences to consider? BTW, the rationale from the security side is that apps which return HTTP 500 may be viewed as "low hanging fruit" by bots randomly scanning for vulnerabilities and prompt further malicious activity. attempts I'm personally not convinced that changing response codes offers any real security gains but am happy to hapy to take the advice of the pros.

View 3 Replies

Add Response Http Headers In Web Configuration?

May 27, 2010

In my application I need to set a http response header. I'd like to do this in web.config. but I dont'know if this is possible and I can't find it on Google. Solution Finally, after a long search I found the solution. Create a class with this code:

public class myHTTPHeaderModule : IHttpModule
{
#region IHttpModule Members
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.EndRequest += new EventHandler(context_EndRequest);
}
void context_EndRequest(object sender, EventArgs e)
{
HttpResponse response = HttpContext.Current.Response;
response.AddHeader("Content-Language", "*");
}
#endregion
}

(Don't ask me why to use this event, but it works..) Now add a line in web.config in the HttpModule section:

<httpModules>
<add type="namespace.myHTTPHeaderModule, assembly name" name="headers" />
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>

View 4 Replies

C# - Exactly Does Response.Redirect("~/...") Put In The HTTP Response?

Nov 24, 2010

I've just finished reading URL vs. URI vs. URN, in More Concise Terms, and it's really helped understand the distinction between the three terms. Since then I've skimmed the RFC2141 and RFC2616 specs and Microsoft's Response.Redirect Method documentation in an effort to answer the following question confidently.

Given this line of code:

Response.Redirect("~/Foo.aspx");

And this resulting HTTP response (trimmed for context):

Status=Found - 302 Date=Wed, 24 Nov
2010 17:27:58 GMT
Server=Microsoft-IIS/6.0
X-Powered-By=ASP.NET
X-AspNet-Version=2.0.50727
Location=/MyWebApp/Foo.aspx

What name(s) most properly describes what has been placed into the "Location" header?

URL? URI? URN? URC? Which is it?

View 5 Replies

Creating Dynamic Http Response From Component

May 14, 2010

I've developed a component which processes online payments. At a specific point the user must be redirected to the selected acquirer web site for authentication. The acquirer itself suggests that there should be a web page which does it. Something such as the following,

<!--TakeOff.aspx-->
<html xmlns="[URL]">
<head id="Head1" runat="server">
<title>@</title>
<script type="text/javascript">
function Go() {
form1.submit();
}
</script>
</head>
<body onload="Go();">
<form id="form1" runat="server" method="post" action="/...">
<div>
<asp:HiddenField ID="MID" runat="server" />
<asp:HiddenField ID="Amount" runat="server" />
<asp:HiddenField ID="ResNum" runat="server" />
<asp:HiddenField ID="RedirectURL" runat="server" />
</div>
</form>
</body>
</html>

This page redirects the user and posts required arguments to the acquirer's web site. Prior to this page there is another page with a payment button (for example). In the click event of the payment button my component is instantiated and required calculation is done. Something such as the following,

protected void btnPayment_Click(object sender, EventArgs e)
{
try
{
var paymentProcessor = new NS.PaymentProcessor(/*required arguments*/);
/*...*/
NS.Result result = paymentProcessor.Calc();
Session.Add("PaymentProcessResult", result);
Response.Redirect("TakeOff.aspx");
}
catch (Exception p)
{
throw p;
}
}

What I'm going to do is to generate [TakeOff.aspx] page at run-time by the payment processor component instead of having static page (I mean aspx pages that are generated during development phase). The reason why is that we may have different acquirers and each acquirer requires its own arguments to be posted. So if the payment processor component generates aspx or even html pages at run-time we do not need recompile and redeploy the web application.

My problem is that I do not know how to generate aspx pages at run-time. I'm not an ASP.NET guru and all efforts that I've made using HttpResponse were in vain as the original page does not transfer the control to the generated page.

View 1 Replies

HTTP Response Behavior - Cause Browser To Prompt

Jan 5, 2011

I have two very similar pieces of ASP.NET code that send a file in an HTTP Reponse to the client. They should cause the browser to prompt to save the file. The first one works, the second one doesn't. The HTTP responses as seen in Fiddler are below.

Working:
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 228108
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
content-disposition: attachment; filename=Report.xlsx
Date: Wed, 05 Jan 2011 12:17:48 GMT
<binary data>

Not working:
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Wed, 05 Jan 2011 12:19:21 GMT
X-AspNet-Version: 4.0.30319
Content-Length: 228080
content-disposition: attachment; filename=report 2.xlsx
Cache-Control: private
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Connection: Close
<binary data>

When the first one is seen in Fiddler the browser correctly prompts to save the file. When the second one is seen in Fiddler, nothing observable happens in the browser. Same behaviour in both chrome and firefox.

EDIT: ASP.NET code that produces the second response

Response.Buffer = false;
Response.ContentType = @"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AppendHeader("content-length", genstream.Length.ToString());
Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}.xlsx", filename));
byte[] buffer = new byte[1024];
genstream.Position = 0;
int n;
while ((n = genstream.Read(buffer, 0, 1024) ) > 0)
{
Response.OutputStream.Write(buffer, 0, n);
}

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved