How do i remove the '.aspx' extension from url [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How do i remove extensions from page URL in c#.
e.g: questions/ask.aspx
I want the url of my web application in following format:
questions/ask
If any one have a idea then pleas guide me...

If you are using web forms you need to add a custom router handler using URL Routing in the Global.asax file.
Check out this sample:
Global.asax
public class Global : System.Web.HttpApplication
{
//Register your routes, match a custom URL with an .aspx file.
private void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("About", "about", "~/about.aspx");
routes.MapPageRoute("Index", "index", "~/index.aspx");
}
//Init your new route table inside the App_Start event.
protected void Application_Start(object sender, EventArgs e)
{
this.RegisterRoutes(RouteTable.Routes);
}
}

You have to Implement URL Rewriting
URL rewriting is the process of intercepting an incoming Web request
and redirecting the request to a different resource. When performing
URL rewriting, typically the URL being requested is checked and, based
on its value, the request is redirected to a different URL
You can Add this in Web.Config
<urlMappings enabled="true">
<add url="~/questions/ask" mappedUrl="~/questions/ask.aspx?page=Ask"/>
</urlMappings>
See Here

Related

Can we control the [Setup] method execution before [Test] Method Execution in Selenium N unit [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Am just wondering how to solve this. I need to automate my company website. There I need to navigate more than one url for a multiple web pages. I have designed Hybrid framework along with Page object Model Design.
My Requirement is,
say I have 3 url's :
www.google.com
www.yahoo.com
Facebook
All the above url and its test data I will keep in an Excel sheet. I have created three different pages and three different test classes.
So my list of questions are:
How to pass url's one by one to [setup] method
how to call the test method deepening upon the url type
Execution Flow need to implement of Application:
You need to parametrize your test with TestCase attribute.
[TestCase("www.google.com")]
[TestCase("www.yahoo.com")]
[TestCase("www.facebook.com")]
public void WebPageTest(string site)
{
driver.Url(site);
//continue with the test.
}
See this article to learn more: https://github.com/nunit/docs/wiki/TestCase-Attribute
Storing URL in excel is not good idea,
You may store URL in app.config file and by using ConfigManager utility you may retrieve those URL from app.config file
As according to your test cases you can use URL where its needed and required
I would suggest you to use [category] attribute to categorise your test cases. For example
[Test]
[Category("GoogleTest")]
public void googletest1()
{
}
[Test]
[Category("FBTest")]
public void fbtest1()
{
}
Now in the [SetUp] method you can load url based on the category, something like
[SetUp]
public void testsetup()
{
#initialise driver
var category = TestContext.CurrentContext.Test.Properties.Keys;
if(category.Contains("GoogleTest"))
{
//category1 setup
}
else if(category.Contains("FBTest"))
{
//category2 setup
}
}
So using this method you can solve query # 2, i.e the url related to the test is already loaded for you, so you can continue with your tests after setup

Localize ASP.NET Identity error messages [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
In my account controller I have something like this:
var result = await UserManager.CreateAsync(user, model.Password);
foreach (var error in result.Errors)
{
modelstateErrors.Add(error);
}
Every error string is localized in English language
What's the best practice in localizing ASP.NET Identity error messages?
Are there any libraries with localized errors, and how are they implemented?
Would it be good idea to switch on every ASP.NET Identity error and return your own localized string?
To localize ASP.Net Identity you need to install one of the following Nuget packages from the Nuget store => https://www.nuget.org/packages?q=Microsoft.AspNet.Identity.Core
You install the package that belong to your culture. So for French culture you should install Microsoft.AspNet.Identity.Core.fr
They all follow the pattern Microsoft.AspNet.Identity.Core.[Culture] where [Culture] is the code fo the culture.
Create e base controller and extend every controller from it
public class BaseController : Controller
{
protected override void OnException(ExceptionContext filterContext)
{
// verify which kind of exception it is and do somethig like logging
}
}
It is one of the best practice por handlling errors, but for the localizing itself do what #codeNotFound said.

how to show different url in C#?

How can i change view like "www.abc.com/welcome" in browser but actual path is "www.abc.com/welcome.aspx".
And when i type "www.abc.com/welcome" then will go path "www.abc.com/welcome.aspx" but still view like "www.abc.com/welcome".
I have try this code on web.config below but got error:Unrecognized configuration section urlMappings
<urlMappings enabled="true">
<add url="~/welcome.aspx" mappedUrl="~/welcome" />
</urlMappings>
I wonder still got other way?
Where did you get the information about this urlMappings section? It's not supported by default by IIS or ASP.Net.
I think you might want to look at the UrlRewrite Module.
With this it's trivial to setup url rewrites like the one you want.
If you're using a URL rewriting module, you need to make sure which version of IIS you will be running on before something like "/welcome" will work. IIS6 doesn't support extensionless URLs by default. You'll need to have an ISAPI filter running for it, or you'll need to run on IIS7.
I suggest you to use routing How to: Use Routing with Web Forms.
You will need to register the UrlRoutingModule and the UrlRoutingHandler handler to be able to use routing feature (more details could be found in the article above).
And then in global.asax
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.Add("BikeSaleRoute", new Route
(
"bikes/sale",
new CustomRouteHandler("~/Contoso/Products/Details.aspx")
));
}

Remove HttpPage Extension in asp.net web application

I want to remove Http Page Extension like this
my actual page:
http://test.com/dashboard.aspx
i need to modify as follows
http://test.com/
for all redirection of .aspx page.
P.s:
i dont want to use URL rewriting.
Use asp.net 4's routing engine. You can specify a routing rule in asp.net 4 as a default route.
Check out:
http://www.xdevsoftware.com/blog/post/Default-Route-in-ASPNET-4-URL-Routing.aspx
for a very basic one that may work in your scenario try this in your global.asax.cs to map everything to say default.aspx
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("Default", "{*whatever}", "~/default.aspx");
}
You can write HttpModule where you can scan incoming url and make all that you want before request will be processed.
http://msdn.microsoft.com/en-us/library/ms227673.aspx

inline to handle url redirect

I am migrating a site from siteA.domain.com to siteB.domain.com. All the page paths remain the same. The problem is it's a gradual migration, and not every path is being migrated at the same time. So what I need to do is check the path the user is going to, and if it's a member of a list of migrated sites, then redirect the user from siteA.domain.com/path to siteB.domain.com/path
I was hoping to add in-line c# code to the master page. Any thoughts/examples of this?
I believe the correct way would be to add some routes to the Global.asax.
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("home",
"home",
"~/Home.aspx");
}
The above code will let you type "http://mysite.com/home" and it will redirect to the Home.aspx page. You could redirect to http://myothersite.com/Home.aspx instead of using the ~, or relative path.
You can add routes for each and every page that you have in some master list.
I would have a list of address in your config that have been migrated, then in the page_load of the master page check the current url (on of the properties in Request.Url I can't remember which) and see if it is the list from the config.
Simple, but quite often the simple way is the best. Plus if it is a temporary thing there is no point wasting time doing anything complex.
Any reason not to use IIS for the redirect? SO Question - How to redirect a URL path in IIS?
Create an IHttpHandler that intercepts all incoming requests and redirects appropriately.

Categories

Resources