Configure ASP To Show Custom Error Page But Still Return Correct StatusCode

Jul 27, 2010

How can I configure ASP.NET/IIS to show custom error pages (i.e. a nice friendly error page), but to still return a 404/500 status code so that google does not try to index the page? I have tried setting the Response.StatusCode to 404, but then the nice error page does not show anymore.

View 2 Replies


Similar Messages:

MVC Custom Error Page (StatusCode 404 Throws A 500)?

Mar 3, 2010

I've got customErrors set in my web.config

XML Code:

<customErrors mode="On" defaultRedirect="/Error/GeneralError">
<error statusCode="404" redirect="/Error/NotFound"/>
</customErrors>

This works fine locally. A 404 throws a 404. On the shared hosting it throws up the standard server 404 page unless I specifically set 404 to point to /Error/NotFound. That's fine. Now it will show the custom 404 page except the response status code is 200. So if I try to throw Response.StatusCode = 404; in my NotFound action in ErrorController like this:

Csharp Code:

[code]....

the server throws a status code 500 Internal Server Error but my GeneralError page doesn't show, just a blank white page with no source.

I've tried many different combinations but I can't seem to find how to make it show my custom 404 page along with a 404 response.

View 11 Replies

MVC :: Error In Subview Master Page Not Show The Custom Error Page On Entire Page ?

Oct 28, 2010

I am showing Custom Error in my page.if somehting happend wrong. but if the same error occured in my subview master page I am not able to show the Custom error page on Entire page its showing me that Error page under subview master page.I am attching the Screen shot.Can any body help me out how to show the Error page on entire page if something happend in any where submaster or other page.Here is the code that I am using in web config file to show custom Error page..

[CODE]...

Here I know the issue what's going on.This issue is occurring because i am using AJAX to partially load the contents of the tabs after the initial page load so the error is occurring AFTER my master page has been loaded.What I need to do is provide a javascript function to handle the error after the ajax call has returned and redirect to the error page.How to write this Javascript and where Do I need to write this?

View 4 Replies

Web Forms :: How To Configure The Validation Error Message In Order To Show Textbox

Jul 26, 2010

i have difficulty to show the validation error message next to textbox. fyi, the error message by default are showing in validation summary.

how to configure the validation error message in order to show next to (on right) a textbox. eg. in index.aspx or edit.aspx.

View 10 Replies

Web Forms :: Show "Custom Error Page" To Redirect To From A Non Existing Html Page

Jul 6, 2010

I want to show a "Custom error page" when i type a non-existing .aspx or .html page in my application. I had followed the same steps in the link [URL] for the HTML pages also but it is working for .aspx pages but not working for .html pages if I enter any non-existing pages. I had added the path of "aspnet_isapi.dll" for the .html extension in the IIS. I also ensured that the check box "Verify file exists" is unchecked while adding the ".html" entry in the "configuration" of the "Home directory" of the website in the IIS but still it is not working.

View 1 Replies

Clearing Page Cache - Show Correct Status Always?

May 16, 2010

I use this type of cache code on my pages

<%@ OutputCache Duration="60" VaryByParam="*" VaryByCustom="browser" %>

An issue by example. I have a page with the asp.net 2 (MSVS 2005) membership menu controls <asp:logonview etc on them. This control show different menus depending on if the member is logged on or not. I am using forms cookie authentication. The sequence of events. Page1 has the above cache settings and a logonview menu control on it. I am not logged on. I goto Page1. I view the page, and the logonvew control shows the button to logon. So correctly it has not detected a membership cookie and shows the logon button. I log on. I go back to page1, yet the logonview has not updated the menu for the newly logon status, as the page is sourced from the cache. I have to wait 60 seconds before the page can be rendered correctly. When the page is updated for logon status, the menu button for logon does not show, it should show Welcome Member Joe Bloggs. How can all pages cache be cleared when a log on happens, so there is not cache limbo, and the logonview menu control shows the correct status always?

View 2 Replies

C# - Page Not Rendered When Sending Statuscode 500 To The Client

Jul 20, 2010

I have a page (generic handler) on which I want to return the status code 500 to the client to indicate that something is wrong. I do it like this:

Response.StatusCode = 500;
Response.StatusDescription = "Internal Server Error";

And at the same time I render a friendly message telling the user that something went wrong. But instead of seing my message, I get the default IIS message saying something like this:

Server Error
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.

And if I go in to IIS and remove the error page for 500, I get this message:

The page cannot be displayed because an internal server error has occurred.

It works as intended in IIS6, but not in IIS7. What should I do to get it working in IIS7?

View 1 Replies

Get A Custom Error Page To Mail The Error Message / Generate A Custom Error Page With The Error Message

Feb 7, 2011

I was wondering if someone could point me in the right direction:

How do I generate a custom error page with the error message and get it to mail me that error message?

Is there a good tutorial out there that someone could point me 2.

View 4 Replies

IIS Configuration :: Show Custom Error Message When Website Is Under Maintenance

Sep 17, 2012

How to show page Error msgs wen user tries to open the page , while tat page is under uploading on the sever?

View 1 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

Is It Correct Pattern To Return Different Views From MVC Controller

Jul 9, 2010

I have an application that has an public 'end user' mode and a 'back office' mode. Both 'modes' pretty much share the same controller logic but the user interfaces for these different 'modes' are radically different. Using the out of box default routing that you get when a project is created for the first time I have something like the following:

Controllers
HomeController.cs
Views
BackOffice
Index.aspx
Public
Index.aspx
Shared
BackOfficeSite.Master
PublicSite.Master
In my HomeController.cs I have logic that looks like this:
public ActionResult Index()
{
var devices = DeviceRepository.FindDevicesByCustomer(100);
if(IsBackOffice())
{
return View(@"~/Views/BackOffice/Index.aspx", devices);
}
return View(@"~/Views/Public/Index.aspx", devices);
}

Is this the correct way to be doing this or am I digging myself an anti-pattern hole? I'm using ASP.NET MVC 2.

View 3 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

ADO.NET :: Linq To Sql Stored Procedures - Set Correct Return Type?

Dec 15, 2010

I've recently inherited an ASP.NET 2.0 project from other developers and they have a LinqToSql datacontext with stored procedures. I've been asked to modify one of the SPs which is essentially just adding a couple columns to the database table and then those to parameters to the SP. So I delete the existing SP from the L2S context and drag in the new one with the additional fields, and all hell breaks loose. Suddenly I get over 20 errors! What seems to have occured is L2S has modified many other stored procedures that I haven't even touched and changed the return type from ISingleDefault<some object> to int. I've never used stored procedures before with L2S so I don't know if this is standard behavior or not. Does anyone know why this has happened and how to fix it to set the correct return type?

View 3 Replies

Architecture :: Ado.net Entity Framework - Query - Return Correct Data

May 26, 2010

I just tring to a complex (for me) with ado.net entity framework this is the structure: In practice it is a sort of group purchasing (Buyers) For each group of purchase (Buyer) should have the opportunity 'to select all products of the brands indicated in buyer I'm doing function to return correct data like this:

public List<Product> GetProductsByBuyer(int vBuyerId)
{
Buyersctx.Products.MergeOption = MergeOption.NoTracking;
return (from lProduct in Buyersctx.Products.Include("Brand").Include("Buyers")
where select lProduct).ToList();
}

View 2 Replies

MVC - JSON + HttpException - Return An Error Page

Jan 30, 2011

I'm trying to return an error page indicating that the user couldnt be found and therefore I throw a HttpException with status code 404, however for some reason it wont redirect to the error page? - Is there some sort of trick to handle error pages with JSON that I should be aware of? My current code:

public ActionResult Details(int id)
{
User userToGet = _session.Query(new GetUserById(id));
if(userToGet == null)
{
throw new HttpException(404, "User not found");
}
DetailsUserViewModel userToViewModel = AutoMapper.Mapper.Map<User, DetailsUserViewModel>(userToGet);
return Json(new
{
HTML = RenderPartialViewToString("Partials/Details", userToViewModel)
}, JsonRequestBehavior.AllowGet);
}

Update - Some more code:

// MyJs.js
function openBox(object) {
$("body").append("<div id='fadeBox'></div><div id='overlay' style='display:none;'></div>");
$("#fadeBox").html("<div style='position:absolute;top:0;right:0;margin-right:2px;margin-top:2px;'><a id='closeBox' href='#'>x</a></div>" + object["HTML"])
$("#fadeBox").fadeIn("slow");
$('#wrapper').attr('disabled', 'disabled');
$("#overlay").show();
jQuery.validator.unobtrusive.parse('#mybox') /* Enable client-side validation for partial view */
}
// List.cshtml
@model IEnumerable<MyDemon.ViewModels.ListUsersViewModel>
<table style="width:100%;">
<tr style="font-weight:bold;">
<td>UserId</td>
<td>UserName</td>
</tr>
@foreach (var user in Model)
{
<tr>
<td>@user.UserId</td>
<td>@user.UserName</td>
<td>@Ajax.ActionLink("Details", "details", "account", new { id = @user.UserId }, new AjaxOptions() { HttpMethod = "GET", OnSuccess = "openBox" })</td>
</tr>
}
</table>

View 1 Replies

MVC Return To Page On Error With Fields Populated?

Jan 13, 2011

I am starting a new project in Asp.net MVC 2.I have been mostly a webforms developer and have limited exposure to Asp.Net MVC and hence this is probably a noob question.

My situation is as follows:

I have a create page for saving some data to the DB. The view for this page is not strongly bound / typed - so the way I am extracting the data from the view is by looking at the POST parameters.

Incase there is an error (data validation, etc), I need to send the user back to the previous page with everything filled in the way it was and displaying the message.

[Code].....

View 1 Replies

Web Forms :: Session_Start Executes Again After An Error Occurs (when Going To Custom Error Page)

Mar 7, 2011

I'm having a wicked time trying to redirect the different error scenarios to a custom error page. Basically, I have put some code in Application_Error in global.asax, and done the necessary web.config settings to use Custom Errors.

In global.asax on Application_Error, I stored the Server.GetLastError in Session. The reason I have to store it in Session is because (as far as I know) you lose the exception when using "ResponseRedirect". And the reason I have to use ResponseRedirect is because I am using an UpdatePanel with AJAX calls, and any exception during the AJAX call shows up as a JavaScript error, and doesn't get handled using the custom error page (see this post).

void Application_Error(object sender, EventArgs e){ ////must perform this check to avoid the "Session state is not available in this context" errors if (HttpContext.Current.Session != null) { Session["LastException"] = Server.GetLastError(); } else { // (I think this happens when there are compile-time errors) Server.Transfer("~/Oops.aspx"); }}void Session_Start(object sender, EventArgs e){ //must perform this check to avoid the "Session state is not available in this context" errors if (HttpContext.Current.Session != null) { //initialize the session (http://forums.asp.net/t/1405077.aspx) Session["LastException"] = ""; }}

View 3 Replies

Web Forms :: Display Complete Exception Details And Error Message On Custom Error Page

Jul 2, 2012

I am trying to handle the unhandled exceptions in my project.I tried with this following code in my web.config filebut it is not at all redirecting to an error page which i have created instead of that it is throwing an exception in my code itselef. How to print the error description over therein my custom error page.

---------------------------------------------------------------------------------------------------
<sys.web>......<customErrors mode="On" defaultRedirect="~/Error.aspx"></customErrors>...</sys.web>
---------------------------------------------------------------------------------------------------

And even i tried in Global.asax page in Application_Error() method like below

 Exception ex = Server.GetLastError();Response.Redirect("~/Error.aspx?errmsg="+ex.message);Server.ClearError();

And in my Error.aspx.cs page i have placed a label and i have written code like this

protected void Page_Load(object sender, EventArgs e)         {
         Label1.Text=Request["errmsg"];
      }

But it is not getting redirected my error page and not displaying anything on it.

View 1 Replies

MVC :: Asp Web Site Administration - Error Occurred - Return To Previous Page And Try Again

Feb 10, 2011

Created an solution containing several class libraries (domain, contracts, etc, etc) and an Asp.Net MVC3 project. Created a database in my local sql server (2008) and ran aspnet_regsql.exe to create the relevant membership and authentication tables. (Though I did not create any code yet that uses it, and plan to just implement the standard forms and membership authentication.) However, when I click on the "Asp.Net Configuration" button in VS (2010), it open the Asp.Net Web Site Administration Tool, but with an error that say "An error was encountered. return to the previous page and try again." (of course there's no "previous page). Only reason i want to use this is actually to create two roles, admin and client. Guess my problem is not knowing where this tool get it's connectionstring from. At present, I got the following in my web.config

[Code.....]

View 4 Replies

Configuration :: How To Create And Configure Custom Handlers In IIS 5.1

Feb 23, 2011

how to create and configure custom handlers in IIS5.1 and also about mapping the extensions in IIS5.1....?

View 1 Replies

How To Configure IIS To Serve 404 Response With Custom Content

Mar 31, 2010

I would like to serve a custom 404 page from ASP.NET MVC. I have the route handler and all the infrastructure set up to ensure that nonexistent routes are handled by a single action:

public ActionResult Handle404()
{
Response.StatusCode = 404;
return View("NotFound");
}

Problem: IIS serves back its own content (some predefined message) when I set Response.StatusCode to 404 before returning the content.

On the VS development web server, this works as intended - the status code of the HTTP response is 404 while my content (the NotFound view) is served.

I believe that when the IIS processing pipeline sees that the application returns 404, it simply replaces the whole response with its own.

What setting in IIS affects this behavior?

I do not have access to the IIS installation so I can not investigate this - however, I can ask the hosting provider to tweak the configuration for me if I know what exactly needs to be changed.

View 1 Replies

C# - Write And Configure A Custom Provider For Ealthmonitoring?

Jan 4, 2011

I'm looking for a walkthrough on how to create and use a custom provider for ASP.Net Healthmonitoring.

So far I've only worked with the e-mail provider that generates e-mails on errors. Basically I want to do the same, but with more flexibility: I want to use the HealthMonitoring features (I don't want to use the Application_OnError event in the global.asax) in a way that allows me have access to an event, that gets thrown like "OnNewHealthMonitoringEntry" with all the information provided in the e-mail, to run custom code.

Edit: Based on the source code provided here [URL] I was able to build my own custom provider and implement it. Now I want to add some new attributes to configure my custom provider.

Here is what the web.config looks like:

<healthMonitoring>
<bufferModes>
<add name="Log Notification" maxBufferSize="1" maxFlushSize="1" urgentFlushThreshold="1" regularFlushInterval="Infinite" urgentFlushInterval="00:00:10"/>
</bufferModes>

[code]....

Is it possible to store configuration necessary for custom provider close to the healthMonitoring section? I guess I could include the settings into the appSettings node, but I'd like to configure it somehow with attributes (inside the healthMonitoring node). Is that possible?

View 1 Replies

MVC :: Want To Do Some Validation To The Data And Then Return A Error Message To The Page It Doesnt Work For Me?

Mar 10, 2010

I got a view that uses the ajax.beginform tag.This works great but if I want to do some validation to the data and then return a error message to the page it doesnt work for me.Here my code :

[Code]....

And the actionResult :

[Code]....

[Code]....

View 5 Replies

Ajax - How To Return An Error From A File Download Action Without Leaving The Current Page

Jul 12, 2010

I am calling a file download action from javascript:

$elem.click(function() {
window.location.href = 'MyController/MyFileDownloadAction';
});

The controller returns a file:

[code]...

This action has a pretty high likelyhood of throwing an exception (or at least not being able to return the file).

Due to the nature of the application (which contains a lot of dynamic content), I can't really redirect to an error page in this situation. The current page needs to stay open somehow.

So I'm ideally looking for something like a javascript pop-up, but afaik this isn't going to be possible since I don't know any way to return a javacript instruction in a non-ajaxed controller call. If I display an error page I need to force it to open in a new window some how. Is there any possible solution to this problem?

View 1 Replies

Custom Error Page For Http Error 503 / How To Fix It

Feb 16, 2010

I need to send a Customized Error page for 503 Errors produced by my asp.net website. I have tried to simulate the condition by switching off the application pool (doesn't work) and by flooding my application with requests. Even though IIS sends me the default 503 error page, and even though I have tried setting a Custom URL in IIS and ASP.NET for this error code, it still returns me the default 503 error page.

View 3 Replies







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