redirecttoaction

Use RedirectToAction in Web API

社会主义新天地 提交于 2019-12-09 17:48:24
问题 I am using RedirectToAction in my ASP.Net WebAPI application and I tried the following one. return RedirectToAction("AuthenticateUser", "AuthenticationServiceWebApi", new RouteValueDictionary { {"userName", model.UserName}, {"password", model.Password} }); This generates the redirection as below. 127.0.0.1:81/authenticationservicewebapi/authenticateuser/admin/admin@123 But, since I am using WebAPI, I need to be the URL like below. 127.0.0.1:81/api/authenticationservicewebapi/authenticateuser

ASP MVC ActionFilterAttribute OnActionExecuting not fired

落花浮王杯 提交于 2019-12-06 09:25:44
I have 2 controllers Home with public class HomeController : Controller { protected override void OnActionExecuting(ActionExecutingContext filterContext) { // do some irrelevant stuff base.OnActionExecuting(filterContext); } public ActionResult Index() { return View(); } } and Service with public ActionResult Confirm() { return RedirectToAction("Index", "Home");} And one ActionFilterAttribute with OnActionExecuting method public class InvitationModeAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { // do some stuff base

Render view to string followed by redirect results in exception

一曲冷凌霜 提交于 2019-12-04 15:12:46
So here's the issue: I'm building e-mails to be sent by my application by rendering full view pages to strings and sending them. This works without any problem so long as I'm not redirecting to another URL on the site afterwards. Whenever I try, I get "System.Web.HttpException: Cannot redirect after HTTP headers have been sent." I believe the problem comes from the fact I'm reusing the context from the controller action where the call for creating the e-mail comes from. More specifically, the HttpResponse from the context. Unfortunately, I can't create a new HttpResponse that makes use of

Use RedirectToAction in Web API

谁说我不能喝 提交于 2019-12-04 05:22:05
I am using RedirectToAction in my ASP.Net WebAPI application and I tried the following one. return RedirectToAction("AuthenticateUser", "AuthenticationServiceWebApi", new RouteValueDictionary { {"userName", model.UserName}, {"password", model.Password} }); This generates the redirection as below. 127.0.0.1:81/authenticationservicewebapi/authenticateuser/admin/admin@123 But, since I am using WebAPI, I need to be the URL like below. 127.0.0.1:81/api/authenticationservicewebapi/authenticateuser/admin/admin@123 How do I do this? I'm not sure how your routing, Web API action signature look like so

Should I be passing values through RedirectToAction or TempData?

我们两清 提交于 2019-12-02 01:27:09
问题 I've seen some articles (even MSDN) suggest TempData for passing data between ActionMethods. But I've seen others here say that TempData should be avoided. What's the best practices way to approach this? Here's some code to show my situation. Note: I'm 100% sure, I'm doing this wrong. Which is why I'm here. :) Also, I've been doing Webforms up until recently. Note2: This is related, but not the same. View: <div> @using (Html.BeginForm("Previous", "Home", new {month = @month}, FormMethod.Post)

Should I be passing values through RedirectToAction or TempData?

白昼怎懂夜的黑 提交于 2019-12-01 22:25:44
I've seen some articles (even MSDN) suggest TempData for passing data between ActionMethods. But I've seen others here say that TempData should be avoided. What's the best practices way to approach this? Here's some code to show my situation. Note: I'm 100% sure, I'm doing this wrong. Which is why I'm here. :) Also, I've been doing Webforms up until recently. Note2: This is related, but not the same. View: <div> @using (Html.BeginForm("Previous", "Home", new {month = @month}, FormMethod.Post)) { <input id="previous" type="submit" value="Previous" /> } // This fails but that's another situation

Rendering a view to a string in MVC, then redirecting — workarounds?

心已入冬 提交于 2019-12-01 06:41:44
I can't render a view to a string and then redirect, despite this answer from Feb (after version 1.0, I think) that claims it's possible. I thought I was doing something wrong, and then I read this answer from Haack in July that claims it's not possible. If somebody has it working and can help me get it working, that's great (and I'll post code, errors). However, I'm now at the point of needing workarounds. There are a few, but nothing ideal. Has anybody solved this, or have any comments on my ideas? This is to render email. While I can surely send the email outside of the web request (store

Rendering a view to a string in MVC, then redirecting — workarounds?

此生再无相见时 提交于 2019-12-01 05:01:36
问题 I can't render a view to a string and then redirect, despite this answer from Feb (after version 1.0, I think) that claims it's possible. I thought I was doing something wrong, and then I read this answer from Haack in July that claims it's not possible. If somebody has it working and can help me get it working, that's great (and I'll post code, errors). However, I'm now at the point of needing workarounds. There are a few, but nothing ideal. Has anybody solved this, or have any comments on

RedirecttoAction with error message

天涯浪子 提交于 2019-11-30 13:25:46
问题 I have a link on a grid in my AdminUsers view grid.Column(header: "", format: (item) => (condition ? Html.ActionLink("Impersonate", "Impersonate", "Admin", new { id = item.username }, null) : Html.Label("Impersonate"), style: "webgrid-column-link"), In the controller, I have public ActionResult Impersonate(string id) { string result = ORCA.utilities.users.setImpersonation(id); if(result == "nocommonfields") return RedirectToAction("AdminUsers", "Admin"); else return RedirectToAction("terms_of

Passing info to another action using RedirectToAction - MVC

六眼飞鱼酱① 提交于 2019-11-30 09:43:17
问题 I have this action: public ActionResult Report(AdminReportRequest reportRequest, FormCollection formVariables) { AdminEngine re = new AdminEngine(); AdminReport report = re.GetCompleteAdminReport(reportRequest); return View(report); } I was wondering how could I go about Redirecting to another action within the same controller, passing the AdminReportRequest, and FormCollection variables? I had something like this in mind: public ActionResult EarningsSalesReport(AdminReportRequest