I want to open web form within MVC 5 project - asp.net-mvc

I am using MVC5 with attribute routing. Below is the code for default route
RouteTable.Routes.MapRoute(
name: "Default",
url: "{controller}/{action}",
defaults: new
{
controller = "Home",
action = "Index"
},
namespaces: new[] { "Web.Controllers" }).DataTokens["UseNamespaceFallback"] = false;
Now I have a requirement to open a .aspx page from this project to render some SSRS reports.
So I add a new folder "Report" and put a .aspx page inside this.
To open this page I just write the url on onclick function of button without using any controller.
To add route for this I used the below route in my Route.config file just above the default route.
RouteTable.Routes.MapPageRoute("Report", "Reports/{ref}", "~/Reports/CustomerQuotation.aspx");
Now the problem is that I am able to open this page from my machine but when I publish the code and deploy this site on dev server and access this url.
This page ask me for authentication, means username and password and If type anything then it shows me 404 request not found.
Please help me on this. I just need to open an aspx page from mvc5 application.

Related

Is possible to publish web application mvc 4 (template 4.5.2) on iis7 using file system as publishing method since vs 2015?

The application in local environment runs well, but when it's published
on live web server displays
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
I solved the problem. Yes, it is possible.
However the default page is not defined in web.config. It must be specified in RouteConfig.cs inside of App_Start directory. Something like this:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
);
As you can see, the absolute path is without cshtml extension, so could be put in url browser something like:
http://server:prort/Account/Login

Server-side routing with an AngularJS SPA

I'm using ASP.NET MVC, IIS 8 and I'm using AngularJS to create a SPA. I only have this routing rule defined in my MVC application, that directs to Index method in Home controller, where my SPA lives:
routes.MapRoute(
name: "DefaultHome",
url: "",
defaults: new { controller = "Home", action = "Index" }
);
Now I have bunch of client-side SPA routes and I want all of them to available without the hashbang prefix #/. html5Mode works perfectly - but only when the app has been loaded. If I copy the URL, close the window, open the window and paste it in, I get an IIS 404 error. That makes sense because the routing is done on the server.
So sharing the URL doesn't work, which I would like to be able to do. So the routing has also to be done server-side, but everytime I change the route (add client side route), I don't want to have to create a server side routing rule.
Can this be done in general? Like something that URL rewrites /* to #/* without redirecting the user? With an exception for /Static.
Simply change the url to "{*catchall}". Like so:
routes.MapRoute(
name: "DefaultHome",
url: "{*catchall}",
defaults: new { controller ="Home", action= "Index" }
);

Changing URL without changing Actual Path to Redirect

I am new to ASP.Net and working on MVC 4. I want to replace my current URL with a customized URL.
For example:
Current URL: http://www.testsite.com/home?pageId=1002
Desired URL: http://www.testsite.com/1002/home/
So the URL that is displayed in the address bar will be the desired one and actual URL working will be the current one.
I have tried URL routing in Global.asax file of my project but doesn't seems to be working for me.
What exactly I want is to put the URL Like this.
Thanks in Advance.
ASP.NET MVC 4 provide a toolbox way to write your application. The URL that you see in the browser comes from Routing that do the hard work to convert url to app routes and app routes to url.
1) The default ASP.NET MVC 4 Template project comes with a file at App_Start folder named RouteConfig, where you must config the routes for the app.
2) The routes has precedence order, so, put this route before the default one:
routes.MapRoute(
name: "RouteForPageId",
url: "{pageId}/{action}",
//controller = "Home" and action = "Index" are the default value,
//change for the Controller and action that you have
//pageId is the parameter from the action that will return the page
defaults: new { controller = "Home", action = "Index" }
);
Now you can enter myappdomain/1220/index for exemple.
Hopes this help you! Take a look here for more info ASP.NET Routing!

MVC default document under folders

So in IIS you can set the default document for all site folders to be say "index.aspx".
In MVC how do I do this across a) all directories or failing that b) one directory at a time.
I have a page in [Views]/[Search]/[index.aspx]
This url works - www.[mysite]/search/index
but I can't get it to work under - www.[mysite]/search
I have tried adding this into global.asax > RegisterRoutes
routes.MapRoute(
"Search",
"{action}",
new { controller = "Search", action = "Index" }
);
MVC doesn't use a default document, but a default route.
Your route above shows us that the default page when someone visits your website (http://example.com) will be the Index view contained within the search directory.
The default route that gets generated with a new MVC project looks like this
routes.MapRoute( _
"Default", _
"{controller}/{action}/{id}", _
New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _
)
What this means is that your routing structure would look like
http://example.com/ (showing the "index" view within the "home" folder)
http://example.com/about/ (showing the "index" view within the "about" folder)
http://example.com/about/contact (showing the "contact" view within the "about" folder)
Normally you don't need this route. The default route should work fine as it specifies a default controller and action which you could modify to match your requirements. Thus if the user requests / this default controller and action should be executed. This would work out of the box on IIS7 but on II6 it won't work because you cannot have extensionless urls by default. You might take a look at the following blog post if you are running on IIS6.

Running ASP.NET MVC in a subdomain makes Html.ActionLink render broken links

I am running MVC in a subdomain
http://test.domain.com which points to the /Test directory on my webhost4life account.
Html.ActionLink("About", "About", "Home")
it renders a link to
http://test.domain.com/Test/Home/About -- which gives a 404
the link should be ..
http://test.domain.com/Home/About
is there a way to override ActionLink to omit the /Test on render?
Thank you
Experiment 1
I added a route to the table like this...
routes.MapRoute(
"Test", // Route name
"Test/{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
and now action link renders links like this..
http://test.domain.com/Test/Test/Home/About/
when this is clicked it does not give a 404 but gives the Home controler About action.
Result
No more broken links but the site renders ugly urls.
For a site using lots of subdomains I use a nifty MVC extension from ITCloud called UrlRouteAttribute. It allows you to assign a route to every action as an attribute setting the path and name. I have extended this to allow fully qualified paths - so to include the domain/subdomain the controller should attach to. If this is something you'd be interested in I'll upload a copy somewhere.

Resources