MVC :: ActionFilterAttribute And Multiple Parameters - Add ",redirect=true"
Mar 2, 2011
I currently have the following ActionFilterAttribute:
[Code]....
No matter the code, the point is that when I use the Filter in my controller, I need to pass in values for both "mem" and "redirect", but I don't know the syntax. All examples I've seen only use one parameter. Is there any way to use more than one or should I revise to a different strategy? As an example, I currently use:
[Code]....
where m is an instance of WBMembership. If I tried to add ",redirect=true" inside the (), I get an error.
I have an action filter for verifying account types that would redirect if necessary by calling filterContext.RedirectToAction(actionName). This doesn't seem to be working anymore.
The main controller action still gets called and then I end up with an error about http headers since it looks like the call to filterContext.RedirectToAction did send back a redirect but then since the controller action still fires, it also sends back content.
What's the right way to redirect to a different action from within an ActionFilterAttribute?
When I want to get the output values its okay but I also want returning a table as a result data.But Datareader has no rows.is it possible if I want a returning query result and multiple output values togather ?I wrote a test above.I can get output values as sqlparameters. But Datareader attached to a Gridview is empty.can you detect whats wrong here and it doesnt return a query result.So stored procedure is not standart or ı am doing something wrong.this doesnt raise any exception.but not returning any data.
I am using Form Authentication and sending an Aajx request to the server for authentication. Based on the json result, the client decides where to go and what to do. That is the reason I am not using FormsAuthentication.RedirectFromLoginPage to not interfere the ajax/json response.In this case Request.IsAuthenticated returns false, even after validating the user with Membership.ValidateUser. Then I set the cookie using FormsAuthentication.SetAuthCookie(username, false)
the code above generates the error as I mentioned at this topic's title. I simply need to refresh my ASP.NET page, I can't use that code instead:HttpContext.Current.Response.AddHeader("Refresh","2");because it says about IIS pipeline modeThe puprose is that I must get into OnLoad method where some conditions are true after refresh/redirect
I am using the EnableCdn=true in my ScriptManager so that WebResource.axd and ScriptResource.axd are overridden with static links to JS libraries at the MS CDN service as follows:
How do I override the CDN URLs or service so that I can retrieve the scripts over HTTPS from the MS CDN service rather than HTTP to avoid the browser mixed mode message? or for that matter a different or my own CDN service entirely.
My issues is this: I want to click on a button in IFRAME1 that will update the page of IFRAME2. Also, i want to pass it some parameters (from aspx textboxes) to change the IFRAME2 output ( content.aspx?value=12&name=bob)
A well-known benefit of MVC is its suitablility for Test Driven Development (TDD) because you can directly call your controller actions from your test methods.
How can you test the combination of a controller action with a ActionFilter attribute (using OnActionExecuted to modify the ActionResult returned by the Action)? If I just call the Action, it returns the ActionResult from the action, but the filter attribute is never invoked. I think maybe you can get it by Controller.ActionInvoker.InvokeAction(controllerContext, "ActionName"), but you have to accurately mock so much of the controllerContext to make it work that it's a real pain.
I would like to create a custom action filter attribute that adds a value in the HttpContext items that would be accessible during model binding.
I have tried to add it in the OnActionExecuting but it that seems the modelbinding is exectued before the filter. Maybe there's a method in the modelbinder that I could override that will be fired after the filter and use the value injected by my filter.
What I want to do, is to inject a validation context (the library I use for validation supports context, it is nvalid.net (www.nvalid.net) I would like to be able to place an attribute such as
[ValidationContext("Prevalidation")]
on my actionresult method, so that the validation that occurs in my custom model binder could know which context to use when doing the Validation. That's why I can't simply make a custom model binder.
I'm using MVC 2 with futures, and I'm trying to hide/show content based on role. Is there a way with ActionFilterAttribute or AuthorizeAttribute if the authentication fails to not show a partial view on a controller all through attributes? Or is all I can do with those attributes is redirect or throw up an error message? I just need the child action to return nothing basically if it fails the authentication.
I found a way using ActionFilterAttribute, but it's kind of a hack because it still calls the ChildAction on the controller and then I'm setting the result to empty afterwards. I'm looking for it not to call the Action/ChildAction at all if the authentication fails. Is there a way to restrict that call?
public override void OnActionExecuted(ActionExecutedContext [code].....
If I have the case where one button is set when the page is displayed and the user changes to the other value, BOTH are coming back as TRUE. How can I just get the value selected by the user?
It took me a little while to figure this out, but the AllowPaging="true" on the FormView seems to be the culprit. I don't have much experience paging from a FormView, but for this requirement the customers wants this kind of UI.I have a FormView with DefaultMode="Edit", which is bound to an EntityDataSource. One of the entity's properties, "ExternalID", determines whether some of the other properties in the entity are read-only. For example, if IsExternal==null, the FirstName, LastName, and Email fields should be rendered as TextBoxes. If IsExternal!=null, the 3 properties should be rendered in Label controls.
I'd Like to be able to have my web service accept multiple POST parameters, some of which will be XML. Is this possible? The code below will generate a server error:
How can I pass two querysting parameters in URL routing using ASP.NET 4.0? I have gone through many articles, but everywhere it shows only one parameter. I'd like the display URL to be: [URL] The first parameter is ID: 1 The second is Name: This is my first report I am trying following route, but it is not working
routes.MapPageRoute( "MarketReports", // Route name "Reports/{*i}-{*n}", // Route URL "~/pageControl2.aspx" // Web page to handle route );
[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string MyWebMethod(string foo, string bar) { // DataContractJsonSerializer to deserialize foo and bar to // their respective FooClass and BarClass objects. return "{"Message":"Everything is a-ok!"}"; } I'll call it from the client via: var myParams = { "foo":{"name":"Bob Smith", "age":50},"bar":{"color":"blue","size":"large","quantity":2} }; $.ajax({ type: 'POST', url: 'https://mydomain.com/WebServices/TestSvc.asmx/MyWebMethod', data: JSON.stringify(myParams), contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (response, status) { alert('Yay!'); }, error: function (xhr, err) { alert('Boo-urns!'); } }); However, this yields the following error (a breakpoint on the first line in MyWebMethod() is never hit): {"Message":"No parameterless constructor defined for type of u0027System.Stringu0027.","StackTrace":" at System.Web.Script.Serialization.ObjectConverter.ConvertDictionaryToObject(IDictionary2 dictionary, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) at System.Web.Script.Services.WebServiceMethodData.StrongTypeParameters(IDictionary2 rawParams) at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams) at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.MissingMethodException"}
I'd like to pass in two string parameters and use DataContractJsonSerializer to write new Foo and Bar objects. Am I missing something?
Which is the best way (in performance and security) to send multiple parameters to a web page (on a different server), considering that the length of the parameters may vary because I'm sending a list of products, and the customer may have selected more than one product, so we need to send each product on the querystring to the other page. For example (I'm on C#); I want to call a web page like this:
(Obviouly considering we can't send special characters via querystring, but I put them here for better understanding) Which will be the better way (performance, security)?
I'm trying to implement a search function on an incident logging page that is working fine. Currently I am only able to search against one criteria at a time, using the following route:
I have an MS SQL function that is called with the following syntax: SELECT Field1, COUNT(*) AS RecordCount FROM GetDecileTable('WHERE ClientID = 7 AND LocationName = ''Default'' ', 10) The first parameter passes a specific WHERE clause that is used by the function for one of the internal queries. When I call this function in the front-end C# page, I need to send parameter values for the individual fields inside of the WHERE clause (in this example, both the ClientID & LocationName fields) The current C# code looks like this:
String SQLText = "SELECT Field1, COUNT(*) AS RecordCount FROM GetDecileTable('WHERE ClientID = @ClientID AND LocationName = @LocationName ',10)"; SqlCommand Cmd = new SqlCommand(SQLText, SqlConnection); Cmd.Parameters.Add("@ClientID", SqlDbType.Int).Value = 7; // Insert real ClientID Cmd.Parameters.Add("@LocationName", SqlDbType.NVarChar(20)).Value = "Default"; // Real code uses Location Name from user input SqlDataReader reader = Cmd.ExecuteReader();
When I do this, I get the following code from SQL profiler:
exec sp_executesql N'SELECT Field1, COUNT(*) as RecordCount FROM GetDecileTable (''WHERE ClientID = @ClientID AND LocationName = @LocationName '',10)', N'@ClientID int,@LocationID nvarchar(20)', @ClientID=7,@LocationName=N'Default'
When this executes, SQL throws an error that it cannot parse past the first mention of @ClientID stating that the Scalar Variable @ClientID must be defined. If I modify the code to declare the variables first (see below), then I receive an error at the second mention of @ClientID that the variable already exists.
exec sp_executesql N'DECLARE @ClientID int; DECLARE @LocationName nvarchar(20); SELECT Field1, COUNT(*) as RecordCount FROM GetDecileTable (''WHERE ClientID = @ClientID AND LocationName = @LocationName '',10)', N'@ClientID int,@LocationName nvarchar(20)', @ClientID=7,@LocationName=N'Default'
I know that this method of adding parameters and calling SQL code from C# works well when I am selecting data from tables, but I am not sure how to embed parameters inside of the ' quote marks for the embedded WHERE clause being passed to the function.