public ActionResult Index()
{
TempData["msg"] = "Test";
return RedirectToAction("About");
}
public ActionResult About()
{
var msg = TempData["msg"];
return View();
}
A simple question. I am sure I will slap my forehead when I see the answer to it.
Navigating to the Index action in the browser results in a redirect to the About action and the TempData value is correct.
Why when I navigate to the Index action using the Fiddler composer it results in a redirect to the About action but the TempData value is lost and null?
I think the answer is found here (http://msdn.microsoft.com/en-us/library/ms178581(v=vs.100).aspx):
"Sessions are identified by a unique identifier that can be read by using the SessionID property. When session state is enabled for an ASP.NET application, each request for a page in the application is examined for a SessionID value sent from the browser. If no SessionID value is supplied, ASP.NET starts a new session and the SessionID value for that session is sent to the browser with the response."
When I add this line to the beginning of each Action:
Debug.Write(string.Format("SessionId: {0}\r\n", HttpContext.Session.SessionID));
I see that when you run from a browser the sessionid is the same. When run from the Fiddler composer they are different.
Therefore, TempData is going to be reset using the default TempDataProvider (which stores the TempData in session state).
If requests are the same than results should be the same. Most likely you are not making exact copy of first request when composing fake one. Note that in case of tempData your composed request will work (get tempData) only if it is the first request with this data - so you have to make "copy" of request that is not yet send by application, you can't replay ones that rely on tempData.
The temp data be stored in the session state and wiped out after first request, so as result it will be invalid/missing if you are not correctly sending it information hand/via Fiddler composer OR (as in your case) making second request with the same information to the same controller.
See also other related questions on the same topic.
Related
I am working on side-project using ASP.Net Core web api. I am currently using Postman so I can interact with custom middleware. As you can see in the picture I have a User id and would like the request header to have more than one value for the user id key. Everytime I debug the api, the request header only counts one value instead of two values. I have looked at the Postman help page but it doesn't really cover any material regarding my issue. So to condense my question, is there a way in Postman that a key (For my scenario, User Id) can hold more than one value.
Your question doesn't really make sense. Postman will send the data you put, to the server. The data you put is "1,2". At the server end, if you pull the userId value and split it on the comma, you have your two values, no?
I find it incredibly unlikely that when you pull userId at the server, the value of the header is "1" and the other id has disappeared. If the web did that loads of headers (such as your gzip, deflate, br there) would get lost and stuff wouldn't work properly
In java with spring boot framework i have idea about it we have to send List userIds from request controller method this method you have to take as post method and send that data into body part with
#PostMapping("/listUsers")
public String getList(#RequestBody List<Integer> userIds) {
// call service method
return "page";
}
Json Request from postman
{
1,2,3,4,5............
}
In dot net core
[Produces("application/json")]
[Route("api/accounts")]
public class AccountsController : Controller
{
[HttpGet]
[Route("servicesbycategoryids")]
public IActionResult ServicesByCategoryIds([FromQuery] int[] ids)
{
return Ok();
}
}
My call to RedirectToAction is acting like RedirectToActionPermanent. That is, the URL is being changed, rather than simply displaying a different view.
Edit: Now that I think about it, RedirectToAction typically acts as a permanent redirect. As in, this is probably the correct behavior. In the below code, if the ModelState is valid, the user is given a 302 redirect back to the index. But then, what's the point of RedirectToActionPermanent?
The redirects are for HTTP errors. I have my Web.config set to point errors to certain action methods in HttpErrorsController. This works perfectly, including showing a temporary redirect, as expected. (https://localhost/ThisPageDoesntExist shows error page but the URL remains the same)
Returning an HttpStatusCodeResult or throwing an HttpException both work as expected.
However, if I try to do a temporary redirect to an error action method by using RedirectToAction, the view is still displayed properly, but the URL changes, e.g. https://localhost/HttpErrors/404.
HttpErrorsController.cs
private ViewResult ErrorView(HttpStatusCode httpStatusCode, string shortDesc, string longDesc)
{
Response.StatusCode = (int)httpStatusCode;
return View("HttpError", new HttpErrorViewModel(httpStatusCode, shortDesc, longDesc));
}
[ActionName("404")]
public ActionResult Error404()
{
return ErrorView(HttpStatusCode.NotFound, "Not Found",
"The requested resource could not be found.");
}
// Other identical methods for each error
ItemController.cs
public ActionResult HttpError(HttpStatusCode status)
{
return RedirectToAction(((int)status).ToString(), "HttpErrors");
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(ItemViewModel viewModel)
{
if (!Request.IsAjaxRequest())
{
return HttpError(HttpStatusCode.NotAcceptable);
}
if (ModelState.IsValid)
{
db.Items.Add(pm);
db.SaveChanges();
return RedirectToAction("Index");
}
return PartialView("_Create", viewModel);
}
Since writing the above, I've realized I'm probably better off just throwing an HttpException, so that it also gets caught by ELMAH, but I'm still quite confused by the behavior described above.
RedirectToAction method sends a 302 response back to the browser with the location header value which the new url and the browser will make a totally new http GET request to this new url. So what you see is the expected behavior.
If you want not do the redirect, but want to keep the url as it is, do not do return a RedirectResult, return a view result as needed.
RedirectToActionPermanent method sends a 301 Moved Permanently response back to the client. This is usually useful when you are moving one page to another (killing an old page and creating a new one with different url) of your site and wants the client to know it so that they can the calling code to use the new url in future. Think about google search engine changing the links to your new page and showing that in the search result.
I am using iframe approach in a .net mvc app and we are setting one return url while sending the request.
My question is how can i know the payment status & ccavenue payment reference no and other payment related params from response url
My retun url action is something like this
[HttpGet]
public ActionResult ResponseCCPayment()
{
//but how to read reposne params from here
return Content("got response frm ccveue");
}
From CCAvenue documentation i can see
redirect_url CCAvenue will post the status of the order along with the parameters to this URL
But no details on what parameters. Can someone help to get this
Login to the merchant account. There you have an option to download the relevant documents about the returned parameters list. (Merchant Account : https://login.ccavenue.com/jsp/merchant/merchantLogin.jsp)
In the Merchant Account you can configure a url to which a asynchronous response will be sent when a customer has made a payment. In this asynchronous response, you can get those payment related info.
There is also a separate REST api method, that takes the order id as argument and return payment related details.
Hope this helps.
I want to make it so that when people search for something, what they searched gets added to the url of the next page. So they can favorite the page, and then access the page again without filling in the form again. All the posts I can fine assume I want to pass in hard coded query string parameters.
When you send an HTTP POST request, the data that the client send to the server are stored in the request's body.
While, when you send an HTTP GET request, you can send data to the client that are in the query string (after the question mark, ?, in form of key/value pairs, ?name=test&age=21) of your url.
That being said, you have to add a filter to your ActionResult method in your controller that allows only HTTP GET request to reach it. For instance, you need something like this:
public class HomeController : Controller
{
[HttpGet]
public ActionResult ActionName(string name, int age)
{
}
}
Then the client can make a GET request using the following url:
www.domain/Home/ActionName?name=test&age=21
I'm building an action that basically handles receiving post data from a flash app,
I have no problem receiving the data.
after that, it should redirect to another controller/action
I tried Redirect, RedirectToRoute, none of them worked.
here is my code
[AcceptVerbs(HttpVerbs.Post)]
public RedirectToRouteResult Draw(FormCollection form)
{
string bitmapDataString = Request.Params["someimagedata"];
byte[] bitmapData = Convert.FromBase64String(bitmapDataString);
File.WriteAllBytes(Server.MapPath("~/Images/abc.jpg"),
return RedirectToAction("Register", "Participant");
}
Redirects are the job of the client (browser). You're simply telling the browser that you would like it to redirect. I don't know anything about flash but note that these redirects don't work with Ajax requests either. I know that's not a full answer but may send you in the right direction while you're waiting on someone with some flash experience.