[英]In C#, how can I make it so it ends .aspx like a directory? Like file.aspx/programtorun/
So I've been using php, and switched to ASP.NET because I love it. 所以我一直在使用php,并且因为喜欢它而切换到ASP.NET。 Anyway... I've been developing my own website and such, but I cannot figure this out for the life of me!
无论如何...我一直在开发自己的网站,但我无法终生解决!
What I have: 我有的:
string val = HttpContext.Current.Request["Header"];
// filename: index.aspx
// what I need to get
if (val == "random")
{
renderA.Random("randoms.html");
}
else
{
renderA.Index("index.html");
}
What it returns in the URI 它在URI中返回的内容
/index.asp?random
What I wish it would look like: 我希望它看起来像:
/index.aspx/random/
Is there someway I can fix this problem? 有办法解决这个问题吗?
You should look at switching to an MVC site; 您应该考虑切换到MVC站点。 it will provide you the functionality you are looking for.
它会为您提供所需的功能。
This is from older releases, but you'll get the idea: Scott Guthrie talking about mvc framework 这是从较旧的版本中获得的,但是您会明白的: Scott Guthrie在谈论mvc框架
I am assuming you are using WebForms and not MVC. 我假设您使用的是WebForms,而不是MVC。 It is called FriendlyUrls and here is a tutorial on Hanselman .
它被称为FriendlyUrls,这是Hanselman的教程。 You might want to consider switching to MVC since it can do this using Routing .
您可能要考虑切换到MVC,因为它可以使用Routing来完成 。
Add a Global Application Class
to your project (Global.asax file), then you can do the following: 将
Global Application Class
添加到您的项目(Global.asax文件),然后可以执行以下操作:
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RegisterRoutes(RouteTable.Routes);
}
void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("random", "random", "~/index.html");
}
You will need a reference to System.Web.Routing
您将需要对
System.Web.Routing
的引用
<%@ Import Namespace="System.Web.Routing" %>
Learn more: 学到更多:
http://msdn.microsoft.com/en-us/library/cc668201.ASPX http://msdn.microsoft.com/en-us/library/cc668201.ASPX
http://www.codeproject.com/Articles/77199/URL-Routing-with-ASP-NET-4-0 http://www.codeproject.com/Articles/77199/URL-Routing-with-ASP-NET-4-0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.