How to redirect to create action page when routing takes place using controller .NET - asp.net

I have tried using controller to redirect to create.html (folder in razor page: pages/CRUD/create).
I added controller name in program.cs using url. Can you help me resolve this issue?
Create controller and redirect to Razor page create action using folder
Link create page to controller
add url in program.cs to redirect to index page by default

Related

Unable to add global AuthorizeFilter when using scaffolded Identity pages in ASP.Net Core MVC application

I created ASP.Net Core MVC project from template with enabled Identity.
I created db from migration files using update-database command.
I was able to run application, register users and login.
I added AuthorizeFilter globally:
builder.Services.AddControllersWithViews(o => o.Filters.Add(new AuthorizeFilter()));
it still worked.
But when I scaffolded Login page using Visual Studio functionality, I wasn't able to login anymore. I was being redirecting to "infinitelly" looped url:
When I remove global AuthorizeFilter:
builder.Services.AddControllersWithViews()
and add it over Action:
[Authorize]
public IActionResult Index()
It works again.
Is there any bug preventing using scaffolded Razor Pages with global AuthorizeFilter?
Or rather I did something wrong or missed?
Global AuthorizeFilter apply on every methods of your project that means your login method too.
I guess your login page is the page where users are redirected to when they are not logged in. so what happen is :
I'm going to login page => login page needs authorization => redirect to login page => login page needs authorization => redirect to login page...
Your login method has to accept anonymous connection cause user is not logged in yet.
Add the attribute [AllowAnonymous] on your login method.

How to rewrite a Path in asp routing?

I am using routing in my asp project and was wondring if it was possible to rewrite the url if a user makes a request to .aspx page ?
I have configured a route as
route.MapPageRoute("Welcome", "welcome", "~/Welcome.aspx");
now if a user makes a request for Welcome.aspx i want to rewrite the url as /welcome.
Use Microsoft.AspNet.FriendlyUrls nuget package.
It will give routing to all pages rewriting the url without the .aspx extension.
No need to write custom routing for all pages individually.

Enable push state in Durandal

I created the single page application with asp.net (empty ASP.NET application)and Durandal.
I have to mention that I didn't use the MVC. Durandal works perfect when i use Hashtag. as soon as I enable the push state the routing is not working and i have 404 error.
so i decided to redirect all page to the index.html page but the problem is after I redirect all requests to index page(to prevent 404 error) the routing doesn't work(because after redirect, URL will be changed to index.html).
how can i fix this issue?
Just FYI:
for test purpose i created separate project and i used MVC application,everything works perfect after I add
routes.MapRoute(
name: "Default",
url: "{*url}",
defaults: new { controller = "Home", action = "Index" }
to Route.config. but i don't want to use MVC.

Redirect to another page in Asp.NEt MVC4

I am creating an application using ASP.NET MVC4 approach. I have a aspx page that is associated to a controller. On the page, I have a link. What I want to do is upon clicking this link I want to redirect to another aspx page which is associated to another controller. How can I achieve this.?
You can use Redirect:
public RedirectResult RedirectToAspx()
{
return Redirect("/pages/index.aspx");
}
Also in your view:
#Html.ActionLink("Redirect", "RedirectToAspx")

Redirect to page not found page if the url does't exist in mVC

I need to redirect the user to page not found page if the url doent exist.
if the user copy the url and paste it on the rbowser, the page shows page not found method.
in this i need to redirect the user to page not found page
See this:
How can I properly handle 404 in ASP.NET MVC?
which refers to this:
http://blogs.microsoft.co.il/blogs/shay/archive/2009/03/06/real-world-error-hadnling-in-asp-net-mvc-rc2.aspx

Resources