ASp.net MVC application Windows Security Pop up - c#

All, I have an ASP.net MVC application (using DevEx controls). I have deployed to a test server via IIS. When I run the application it gives the below pop up for the home page.
testserver:1234
If I navigate to other pages, testserver:1234/page1 , testserver:1234/page2 it works.
has anyone encountered same issue? Do you know why am I getting this pop up on home page testserver:1234. Thanks for helping out.
This how my controller looks:
public ActionResult Index()
{
ImportDataValidationErrors = new List<ImportFileRecord>();
return View();
}
and this is how routing looks:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "ImportData", action = "Index", id = UrlParameter.Optional }
);
}

Related

URL path to the MVC project

I have a MVC application, I try to run the application but I can not get any page in Browser, I am guessing the path has some problem.
This is RouteConfig:
public class RouteConfig {
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.ashx/{*pathInfo}");
routes.MapRoute(
name: "Default", // Route name
url: "{controller}/{action}/{id}", // URL with parameters
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
}
This is HomeController:
public ActionResult Index()
{
ViewBag.Message = "Welcome to DevExpress Extensions for ASP.NET MVC!";
return View();
}
This is the View's path:
Views -> Home -> Index.cshml
#Html.DevExpress().ReportDesigner(settings =>
{
settings.Name = "ReportDesigner";
}).Bind(new DevExpressDemo.Reports.Report1()).GetHtml()
This URL is in Project URL: http://localhost:53975/
When I run the project I go to this URL:
https://localhost:53975/Home/Index
But this is the response I am getting in Browser:
This site can’t provide a secure connectionlocalhost sent an invalid response.
When I go to http://localhost:53975/ it convert it automatically to https and shows : This site can’t provide a secure connection
You are trying to access it through https rather than http. Go to http://localhost:53975 in your browser and see if that works.
change HTTPS to HTTP on yourr brrowser address bar

C# MVC Redirect a dynamically specified route to a fixed action

I am using C# MVC.
I have an action which looks like this.
public class CustomController : Controller
{
public ActionResult CustomPage(int customPageId)
{
var model = new CustomPageViewModel()
{
customPageId = customPageId
};
return View(model);
}
}
I want to be able to hit this action but to use a different route. For example I want Home/Index to actually hit this action, but to report in the URL that its Home/Index.
My custom pages are stored in the database which tell it what route to have, how can I create routes for my pages programatically and have MVC perform the required actions?
As this is a CMS based system, I don't want to have to create a Home/Index controller and action, as the user may choose any route they wish.
Thanks, Tom
FYI: I have sort of figured this out. Unfortunately Routes are defined when the application starts, so I have to force a restart if I want to setup a new route while the app is running...
Here is the code I have used to setup my routes incase it helps anybody else.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
var pageList = new PageService().Get();
foreach (var page in pageList)
{
var targetRoute = string.Format("{1}/{2}", page.PageArea, page.PageController, page.PageAction);
if (!string.IsNullOrWhiteSpace(page.PageArea))
targetRoute = string.Format("{0}/{1}/{2}", page.PageArea, page.PageController, page.PageAction);
routes.MapRoute(
string.Format("PageBuilder_{0}", page.PageId),
targetRoute,
new { area = "Builder", controller = "Build", action = "Index", pageId = page.PageId }
);
}
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}

ASP.NET MVC 4 Parameters Separated by Forward Slashes "/" not passing args properly

I am trying to follow a convention used by many sites that pass in arguments with multiple forward slashes, as opposed to using the GET model.
That is, I am looking to consume a URL like:
http://www.foo.bar/controller/action?arg1=a&arg2=b&arg3=c
In this fashion:
http://www.foo.bar/controller/action/a/b/c
I currently have this (mostly) working, using the following:
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Sandbox",
url: "Sandbox/{action}/{*args}",
defaults: new { controller = "Sandbox", action = "Index", args = UrlParameter.Optional }
);
}
However, if I pass in something like
http://www.foo.bar/Sandbox/Index/a
or
http://www.foo.bar/Sandbox/Index/a/
The Controller and action are appropriately called:
public ActionResult Index(string args)
{
return View();
}
but args is null.
However, if I pass in something like:
http://www.foo.bar.com/Sandbox/Index/a/b
Then args is "a/b", as desired.
I have been scouring SO and the rest of the web, but can't seem to find the solution.
Is there something obvious I am missing to correct this behavior?
Am I looking for the wrong terminology?
Note: I was able to repro this issue with a brand new ASP.NET application using Windows Authentication. All that was done:
Create ASP.NET application in VS 2015
Choose MVC
Click on Change Authentication
Select Windows Authentication
Add the above Map Route to RouteConfig.cs
Create SandboxController.cs and add the args parameter to Index
Create the Index.cshtml view
Repro the problem using http://localhost:55383/Sandbox/Index/a
Repro the expected behavior using http://localhost:55383/Sandbox/Index/a/b
Any help is very appreciated. Thank you!
Similar question, but doesn't help me: URLs with slash in parameter?
Never mind... Here is the problem...
The MapRoute is calling the default route, first.
To fix it, I just swapped the Default map route with the Sandbox route.
I hope this helps someone.
Working Solution:
public class RouteConfig {
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Sandbox",
url: "Sandbox/{action}/{*args}",
defaults: new { controller = "Sandbox", action = "Index", args = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}

MVC to web form redirection without changing URL

my requirement is, there will be one controller method, which will handle all the request, that might return MVCview/model, or it might return .ASPX page, in any case URL must be same.
something like following.
public ActionResult HandleRequest()
{
if(Module is Converted)
{
return view(ModuleName);
}
else
{
//return module.aspx page, Here I can user Redirect method but it will change URL
//I don't want browser's Url to be changed.
}
}
Your answer is Routing.
http://msdn.microsoft.com/en-us/library/cc668201.aspx
Look at following code :
public ActionResult Test()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return RedirectToAction("TestAspx");
}
public ActionResult TestAspx()
{
ViewBag.Message = "Your app Test aspx page.";
return View();
}
Here the action TestAspx() returns an TestAspx.aspx view.
And for the Routing
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"TestAspx",
"testganesh",
new { controller = "Home", action = "TestAspx" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new {controller = "Home", action = "Index", id = UrlParameter.Optional}
);
}
Please make appropriate changes to the routing names that you need.
Hope this will help.
Let me know if you still face any issue.
Mark as right if the issue got fixed.
:)

How to specify route options to specific controllers in ASP.NET MVC 5

I would like to suppress the controller from the route, and it worked fine using this:
routes.MapRoute(
name: "HomePages",
url: "{action}",
defaults: new { controller = "Home", action = "Index" }
);
The problem is when doing the same for a different controller like "Account", the first option only will take effect :
routes.MapRoute(
name: "LoginRoute",
url: "{action}",
defaults: new { controller = "Account", action = "Login" }
);
My objective is to hide the controller from the route, so i can directly access mysite.com/login and mysite.com/index, how to achieve that when login is under Account controller and index is under Home controller?
How to specify the second option for the Account actions, and keep the first for the Home actions?
Have you thought about using the Routing attributes e.g:
[Route("{getId:int}")]
public ActionResult Show(int getId) { ... }
you can use this in conjunction with the old way of routing. You do need to explicitly set this functionality in your config:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
}
}
I have found the routing Attributes makes it very easy to set good routes on my controller methods. This also bleeds into web api and RESTFul stuff as well.

Categories