Abort/cancel Action And Response From ActionFilter?
Mar 3, 2011
Best way to abort/cancel action from ActionFilter
I've got this ActionFilter, and it's suppose to end the connection immediately and return a 401 Unauthroized:
public class SignInRequired : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)[code]....
I learned how you can cancel the action from executing by setting 'context.Result = new EmptyResult()` here, but I'm not sure if this is the best way to flush the response and close the connection.
View 1 Replies
Similar Messages:
Apr 27, 2010
How can I unit test an action which alters the Http Response object? I haven't been able to solve this. I can mock the object but can't see how I can check the value after the action runs. I set the Response.StatusCode when errors occur in ajax requests and need to check it has been set in the unit test. The only alternative I can see is to change all my actions to return json objects with a IsSuccessful flag or similar.
View 5 Replies
Mar 18, 2011
Is there a way of modifying the response in OnResultExecuted? Like reading the current response and writing it out again?
I want to replace date string in JsonResult after the object was serialized.
View 6 Replies
Mar 20, 2011
I wanted to create a CurrentUser object to be accessible in every Action of Controller, I initialized it in Constructor but User.Identity was not available in Constructor. I followed the following link on stackoverflow:
Defining a User with User.Identity.Name in controller constructor
But after inheriting my Controllers from BaseController, my Action methods are not even executed, the execution stops at Execute of BaseController and I get blank pages in the browser.
View 1 Replies
Oct 28, 2010
I am using a LINQ to SQL data source for a ListView and perform a validation check in the Listview ItemUpdating event:
[Code]....
This works great and keeps the user from updating the record with invalid data.However, when I hit cancel after this operation, it saves the text in the box rather than cancelling the operation. Here's my code for the update button:
[Code]....
Update Function:
[Code]....
I do not handle the cancel button event, as the cancel operation has worked fine... unless someone enters incorrect information and e.Cancel is set to true.What am I doing wrong? Is it the mixture of using the LINQ Datasource and doing my own updating?
View 1 Replies
Oct 29, 2010
I have a text box that I am reading mulitple employee names into. If the user enters a name that does not belong to an employee I want to cancel the item_updating function. Here is my code:
Dim RECIPIENTS() As String
RECIPIENTS = RLIST.Split(";")
Dim NAME As String
[code]...
View 4 Replies
Mar 18, 2010
I have two custom ActionFilters on an action. In first of the actionfilters, I have an redirect performed if a condition is not met (classic authorization). And in another I have an redirect performed if another condition is not met (say role checking). But I do not want to continue to the second actionFilter if the first one is not met. How to do this?
View 1 Replies
Dec 2, 2010
I have datagridview with 2 columns. SortMode of first is set to Automatic.
In this grid is a lot rows, and when I change value in the row, for example from xyz to abc I still in position where this row WAS. Edited row jumps to top.
I want to abort this automatic sorting and I want call sorting by left click on column. Be
I found some solution (code below + I set SortMode to Programmatically), but my row still jumping :/ Has anyone solution to tackle with this issue?
private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
DataGridViewColumn newColumn =
[Code]....
View 1 Replies
Dec 17, 2010
I am using Actionfilter to globally filter our HTML comments from all action methods and in all controllers. It simply overrides OnActionExecuting and runs the response through a regex to filter the comments. I am also using RenderAction to render some more complicated widgets in my website. There is no caching in place, I just use Renderactionto keep my code as simple possible.
When calling RenderAction from within a Razor View, I get an error message telling me that "Filtering is not allowed". The problem does not occur when calling RenderAction from within an aspx View. It only occurs when calling RenderAction from within a Razor View. In case it matters: the view being rendered is implemented with ASPX. Is this a bug or a known limitation?
View 6 Replies
Oct 13, 2010
I have a action filter:
[Code]....
Once the action filter handles the validation, instead of redirecting to another pages is it possible just to return the view associated with the action with the updated modelstate? Basically this is to handle business validation exceptions thrown by the business layer in a generic way.
View 2 Replies
Feb 25, 2011
what are the possible cases/causes for a thread abort exception? and how can we re-produce the same scenario if such exceptions can only be found on live production environment?
is it possible to access session variables when such exceptions occur or will session variables also get flushed and no longer be available? if we are able to manage/handle such exceptions, then will our application will continue to provide us a log for success/failure case of any particular task/process from where it was stopped?
View 3 Replies
Jul 12, 2010
I have a common base class from which all my ASMX webservice classes will inherit. In the constructor, I want to do some common authentication checks; if they fail, I would like to halt processing right away (subclass's code would not get executed) and return a 401-status-code response to the caller.
However, the common ASPX-like ways of doing this don't seem to work:
Context.Response.End(); always kicks back a ThreadAborted exception to the caller, within a 500-status-code response. Even if I explicitly set Context.Response.StatusCode = 401 before calling End(), it is ignored. The result is still a 500-response, and the message is always "thread-aborted-exception". MSDN suggests I use HttpContext.Current.ApplicationInstance.CompleteRequest() instead. However, this does not stop downstream processing: my subclass's functions are still executed as if the constructor had done nothing. (Kind of defeats the purpose of checking authorization in the constructor.) I can throw a new HttpException. This is a little better in that it does prevent downstream processing, and at least it gives me control over the exception Message returned to the caller. However, it isn't perfect in that the response is still always a 500. I can define a DoProcessing instance var, and set it to true/false within the constructor. Then have every single WebMethod in every single subclass wrap its functionality within an if (DoProcessing) block... but let's face it, that's hideous!
Is there a better / more thorough way to implement this sort of functionality, so it is common to all my ASMX classes?
edit: Accepting John's answer, as it is probably the best approach. However, due to client reluctance to adopt additional 3rd-party code, and some degree of FUD with AOP, we didn't take that approach. We ended up going with option #3 above, as it seemed to strike the best balance between speed-of-implementation and flexibility, and still fulfill the requirements.
View 1 Replies
Jan 22, 2010
I wrote a webcrawler which calls a web page in a do while loop amount 3 seconds
totally there are 7000 sites... i parse the data and save it in my DB.
sometimes because the script is loading for a long time, i got a timeout in browser,
but in background i continues. I see that on my database.
Can I prevent this?.. Now it's just possible if I stop webserver.
View 2 Replies
Feb 15, 2011
My Original Issue here:Help! I've got repository access in my MVC master page! Refactor time!What originated as a re factoring job to improve performance has revealed new issues. If I should keep this in my original question - feel free to delete this one, and rename the old one to something more relevant. I'm using an ActionFilter applied to a base controller to load some user-customized settings. My issue is that I save these settings in the filterContext.Controller.ViewData object but its coming through as null on my master page. Here is the relevant code:
Action Filter
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class StoreSettingsActionFilter : ActionFilterAttribute
[code]...
View 1 Replies
Mar 12, 2011
I am trying to make ActionFilter which redirects banned users to /Error/NoAccess site, so I have ActionFilter:
[Code]....
Before each public class xxxxxxController : Controller I use [NoBannedUsersActionFilter]. But for example on website /Account/LogOff I have error: 'Server cannot modify cookies after HTTP headers have been sent.' and VisualStudio shows me AccountModel.css file and this method:
[Code]....
View 3 Replies
Nov 3, 2010
AjaxControlToolkit.ToolKitScriptManager.OnInit() throws thread abort exception for every aspx page. I have an asp.net 2.0 Ajax application, where I have set the following properties of ToolScriptManager on my pages.
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnableScriptGlobalization="true"
EnableScriptLocalization="true" CombineScripts="true" EnablePageMethods="true">
<Scripts>
I have this configuration on all the aspx pages in my application. When I checked the .NET CLR exception Performance counter I figured out a large number of exceptions, mainly one exception per page load is occuring. On running windbg I was noticed that
AjaxControlToolkit.ToolKitScriptManager.OnInit() has the following code block which is getting executed. The OutputCombinedScriptFile() returns true. But since I am setting my controls on DesignTime still designmode is set to false for toolkitscriptmanager.
if (!DesignMode && (null != Context) && OutputCombinedScriptFile(Context))
{
// This was a combined script request that was satisfied; end all processing now
Page.Response.End();
}
I am not sure if this is a reported bug or even a bug with ajax, but this is causing havoc in my load test results as I have around 3 hundred thousand HTTP requests to be handled per day out of which 80% are aspx page requests resulting in a large number of threadafbortexceptions, thus affecting the performance.
View 3 Replies
Nov 29, 2010
I'm implement Comet in Asp.net MVC, I used timer to keep Async request in server, Async request will complete when timer elapsed 1 minute and response to client (to avoid 404 error) and then reconnect to Async Controller. I also wanna execute some Synchronous action during Async request was holding, but the problem is: When an Async action was executed and hold by using timer, the Sync Action wasn't called until Async action (comet long-live request) completed. I did test with firefox 3.6 many times, but the result is the same, so strange, Do you know why ? I have a sub some questions : To implement comet, using timer (response after some minutes elapsed) or thread (response after several time sleeping thread) to hold async request, which is better?
View 1 Replies
Mar 23, 2011
I am desiging a master and details page from a search page..user can search for something and I need to display the result in jqgrid if the result has more than 1 row or record.. if the result is just one record then i have to directly send then to details page by skiping grid page... I do have an action method for results page and one more action method for Jqgrid data..i am trying to check the row count for the database result and trying to redirect to details action results..but its not working at all..and showing an empty jqgrid..
[Code]....
View 9 Replies
Apr 29, 2010
Lets say I have a simple controller for ASP.NET MVC I want to test. I want to test that a controller action (Foo, in this case) simply returns a link to another action (Bar, in this case).How would you test TestController.Foo? (either the first or second link)
My implementation has the same link twice. One passes the url throw ViewData[]. This seems more testable to me, as I can check the ViewData collection returned from Foo(). Even this way though, I don't know how to validate the url itself without making dependencies on routing.The controller:
public class TestController : Controller
{
public ActionResult Foo()[code].....
View 1 Replies
Jun 12, 2010
My httppost action doesnt seem to have received my model. The code is below;
[Code]....
i put a breakpoint on the line; return RedirectToAction("Error", "Dashboard"); and i found that appQualif carried no values whatsoever from the form i submitted..
View 5 Replies
Jun 30, 2010
I've been using Html.Action("ActionName", "ControllerName") to invoke child actions across controllers without needing to have the view in ViewsShared. This has been working great for displaying things like session or cookie information.
Instead of just accessing cookies, I would like to pass additional parameters to Html.Action("ActionName", "ControllerName") so the action can execute different code based on the the data passed to the original view.
Should I be using a different method to pass parameters to a child action in a different controller?
View 1 Replies
May 20, 2010
I'm trying to add file upload functionality to a page. I've got a form that posts the selected file to a controller with a 'savefile' method. But if I don't add a get version of 'savefile' I'll get a 404 error. Here is the form code which is presented on the Index page:
[Code]....
And here is the controller code:
[Code]....
Intuitively I don't think I should need a GET version of SaveFile but if omit it I get a 404 error when the form posts. Why should I need a GET version of SaveFile when all I want is to post a form and save the file?
View 4 Replies
Jun 21, 2010
Does any one know how to dynamically add ActionFilter to an Action?
View 3 Replies
Nov 12, 2010
I have a controller with a bunch of actions as such:
[Code]....
I'm looking for a way to find out which action invoked the other: for instance, when redirecting to Action1, I need to know whether it is coming from clicking "next" button at Action0 or clicking "back" button at Action2. This is is to avoid performing Action1 twice (My app is like a wizard, if I click back button at Action2, I don't want to execute Action1 again).
View 1 Replies
Mar 3, 2010
I am not able tto understand the differnce between REspose.Expire and Response.ExpiresAbsolute?
Is it mandatory to use both toghter?
View 4 Replies