|
I am working with ASP.NET MVC 4 using Visual Studio 2015 community edition, and IIS 8.. I am beginner in this technology..
I created login page,
In my Login controller (action Index), I put return RedirectToAction("Index", "Home") to redirect the page when users enter correct username and password.. it works when I debug/run it in visual studio environment.. but when I publish it (let say the name is MyPublishedWeb), create application in IIS, and browse it, the URL will look like this: localhost/MyPublishedWeb/Login/Index
The problem is when I login succesfully, it redirects me to localhost/Home/Index, instead of localhost/MyPublishedWeb/Home/Index, and it gives error..
But when I change RedirectToAction() to Redirect(), it work both in Visual Studio environment and IIS..
What do I miss?
Why RedirectToAction() doesn't work in IIS application?
|
|
|
|
|
Without knowing your routes, you can use "/" as the url as it normally defaults to Home/Index
|
|
|
|
|
I writing a project about product management. Now I want scan barcode of a product when I import/export to store. Can you help me?
|
|
|
|
|
|
|
Most scanners are fairly straightforward devices which read a barcode and return a string containing the actual product number. The issue you need to consider is where the scanner will be connected. If you are trying to do this into a website then how will the users get access to the scanner?
|
|
|
|
|
I'm having a hard time finding anything on this on the internet possible because I don't how to word the question properly.
So I'm reading the Chapter on Routing in Professional ASP.NET MVC 5 and on the second page they have a list of requirements for high-quality URLs. One bullet point is that a URL must be hackable, that is the end of the URL can be hacked off and still work. So I am currently adding handling for this into the controllers of a test project but I can't figure out how to do something.
For example, say I have a controller
public class DepartmentController : Controller {}
With a Details action
public ActionResult Details(int? id)
{
}
I did figure out out that by making the parameter nullable, the controller doesn't error when passed a URL like: http://www.somesite.com/Department/Details that is lacking a parameter therefore fulfilling the hackable requirement. My question is on handling it.
All of the examples I can find pretty much mirrors this:
public ActionResult Details(int? id)
{
if (id == null)
{
return RedirectToAction("FourOhFourError", "Errors", null);
}
else
{
{
}
What I would like to know how to do is to return nothing. Is there a way not to return a redirect or is that impossible with an HTTP GET (i.e. the server must return something to the client)?
I found this which, turns out, is the same as returning null:
return new EmptyResult();
but this just redirects the browser to an empty page. Is there a way to not do anything and have the browser stay on the same page or is that not how the HTTP protocol works?
if (Object.DividedByZero == true) { Universe.Implode(); }
|
|
|
|
|
How about returning a specific view?
public ActionResult Details(int? id)
{
if (id == null)
{
return View("EmptyPage");
}
}
That would render the view located in ~/Views/Department/EmptyPage.cshtml
If you wanted to render a view from a different folder, you should be able to pass the app-relative path of the view:
return View("~/Views/Common/EmptyPage.cshtml");
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
What I am trying to figure out is how to not redirect at all. Let me try to expand a bit. From the end user point of view, say they browse to the URL http//:www.somesite.com/Departments/Details/5. Now, for some reason they backspace the '/5' off the end of the URL and hit enter. Is there a way to have their browser stay on the same page without redirecting or is that not possible. Handling the null parameter in the controller and returning a redirect to another page seems to be the only answer unless a session state is introduced which, to me, is defeating the whole purpose of making MVC stateless.
if (Object.DividedByZero == true) { Universe.Implode(); }
|
|
|
|
|
But returning a specific view doesn't redirect. It just displays that view.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
try
return null;
or get the calling url from the request context and redirect to it
|
|
|
|
|
Using the request context to get the calling URL, didn't think of that. Can you provide a little code snippet on I how I do that?
if (Object.DividedByZero == true) { Universe.Implode(); }
|
|
|
|
|
string requestUrl = System.Web.HttpContext.Current.Request.Url.ToString();
|
|
|
|
|
Ah, just the same as with web forms. Thanks.
if (Object.DividedByZero == true) { Universe.Implode(); }
|
|
|
|
|
The ideal thing is that you won't hit that endpoint again from the originating url.
you could also try to return a PartialViewResult where the Content is set to a blank string ""
|
|
|
|
|
This seems a lot harder than if you were using AJAX and return PartialView().
|
|
|
|
|
I know. I was just asking if there was a way to not return anything from a [HttpGet] controller action that would normally return a View. It would appear to be impossible to just not return anything. I am beginning to think that it might be a part of the HTTP standard that a GET message from the client must return something from the server but I am not that knowledgeable on the particulars of the HTTP protocol.
if (Object.DividedByZero == true) { Universe.Implode(); }
|
|
|
|
|
No, not out of the box. The closest way to return nothing from an ActionResult returning method is the aforementioned EmptyResult.
That said, there is a way to do something similar by adding a route and a void method.
RouteConfig.cs
...
routes.MapRoute(
"DetailOverload",
"Department/Details",
new { controller = "Department", action = "VoidDetails" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
DepartmentController.cs
public void VoidDetails()
{
}
public ActionResult Details(int id)
{
}
This is basically the .NET MVC baked-in way to modify action calls.
|
|
|
|
|
Ah, so it is possible by putting it into the route config file and pointing it to a void controller function. Why didn't they write this to be something intuitive, like returning NULL to the view engine? Instead, you have to modify routing to catch a hacked path in order to have the server not return anything to the browser.
In the end, I guess it would be simpler to check for hacked paths and redirect to the site homepage if found. Is there any pseudo-standard handling of responses to hacked paths?
if (Object.DividedByZero == true) { Universe.Implode(); }
|
|
|
|
|
Well, the fact is this behavior breaks the expected functionality of HTTP; the appropriate response by convention would be to return an HttpNotFound() if the id is not set or null, or send down a view with a list of possible values.
Generally the expected behavior for HTTP is to send a request and get a response of some sort. Black-holing the response is just not the norm.
All that said, I wasn't in on the meetings where they defined the standards that were going into MVC (it'd hopefully be less cluttered if I was )
And to answer your question, you're overthinking that. I went back and re-read your initial post and have a much better solution for you:
DepartmentController.cs
{
public ActionResult Details(int? id)
{
if(id == null)
{
return View("Home");
}
}
}
No new routes or anything needed.
|
|
|
|
|
Nathan Minier wrote: Well, the fact is this behavior breaks the expected functionality of HTTP; the appropriate response by convention would be to return an HttpNotFound() if the id is not set or null, or send down a view with a list of possible values.
Generally the expected behavior for HTTP is to send a request and get a response of some sort. Black-holing the response is just not the norm.
I was kinda expecting this.
It explains why the other answers were all along the lines of 'Just redirect to X.' Thank you for taking the time to explain that it is possible and how it can be done but also why it is not recommended. I learned something new today.
Thanks.
if (Object.DividedByZero == true) { Universe.Implode(); }
|
|
|
|
|
in the aspx form contain 1 text box and search button.
when enter some text in text box and click search button.
when we click the button then open a pdf file and hilight the text that are given in the text box with background colour
|
|
|
|
|
Hi All,
I am using ORM tool NetTiers for my Web Application, I don't know the reason but my NetTiers setting weren't saved in the .cst file and I missed the .csp file, I don't know which file saves all my settings.
When VM was restarted all the settings are lost now when I am trying to generate the code again using Nettiers, it is creating the Delete methods twice and giving me error.
Can anybody please help me which settings I should make in NetTiers to not to do it and to save those changes in some where?
Any help is much appreciated buddies, a code snippet, a link or even suggestion.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Hello All -
I'm trying to find best technique to handle the situation where my web page (.aspx) stay active ( able to edit and click items on it) while part of the screen showing a update bar indicating that asynchronous function is still active. When that task gets over server sends the message out to page with link to a .txt file ready to download.
I read up on Async/Wait; And it can start the Asyn task but I could not figure out how to send the message out to client upon tasks completion.
I'm open to any technique that works not married to async/await. I code in VB. Any pointer/suggestions/links are appreciated!!
Thank you!!
Ajay Sharma
|
|
|
|
|
I have a form with 3 related dropdownlist and a text input.
That means the first dropdownlist filter the second dropdownlist calling an webapi, the second dropdownlist filter the next dropdownlist calling another webapi.
At document.ready, I fill the dropdownlists with default options.
Of course, I map the dropdownlist's on change event to fill according the parente dropdownlist selection.
Now, if the user fill a code into text input, all dropdownlists must be updated, according the input code.
The first dropdownlist is working fine, but none of the other two are filled.
Can someone show me some example about how to do it?
Thank you.
Luís Oliveira
|
|
|
|