Any way to set project property from code? - c#

In MVC, if you navigate to the Properties of the project and go to the Web tab, you can set a specific page. I was wondering if there is any way to do this from the code?

I don't think so. That page is for VS to know what page should launch when you press F5. If you just want to set the default page for the application (when no page is called) just set the desired action and controller in the default route.
Maybe you have a specific purpose to want that?

In MVC, there was no relation with physical file in webserver and the URL in browser. (It use routing system with URL mapping rules, which map incoming URLs and route to the right Controller and Action method.)
So you cannot set specific page as "Startup Page" like in normal WebForm. Even if you can do in VS, this will open with file extension (*.aspx, *.cshtml) in browser. You need to create your own default route.

Related

Asp.net routing between different web forms

I am creating a website and I'm trying to implement routing feature. Most of the time it works fine, but I've found a problem while routing between different web forms placed at different levels from the root of the website.
The above picture shows all the routes defined and picture below shows the solution explorer of my project:
Home page(home.aspx) of my website is shown below:
On clicking the picture it opens a new page(singlepage.aspx) with whole article about the topic and contains the required url(sitename/heading/querystring):
But from there when i click on HOME button, it does not take me to home page, but instead gets me to the url like this:
Seems like it is not calling the "routeHome" route, instead calls "routeSinglePage".
This is how the html for taking us to HOME page is:
So I wanted to know how I can get it to the home page from singlepage.aspx by clicking on HOME button. Do I need to add new routes or something else.
Thanks
Change the HTML to:
<li>Home</li>
<li>About</li>
<li>Contact</li>
The "/" indicates an absolute path, you are currently using a relative path and hence the issue.

Visual Studios Launches Wrong URL With ASP Project?

I'm working on an ASP project, and probably will be for a very long time. Which is fine with me because I've fallen in love with MVC, it completely eliminates -most- things I hate about web dev. That said, I has a problem..
So, I right clicked a new index and set it as the start page and now it sends me to..
http://localhost:9240/Views/Home/Index.cshtml
But the URL that works is http://localhost:9240/Home/Index
So when I start the project it 404's
In mvc you don't set startup page. To set a default page you can follow below steps.
Right click on your project and go to properties and select start url and write your page url.
Hope it works
You should not set the start-page on your view file, MVC is not like web-forms as you start the project it will go to http://localhost:9240/Home/Index by default if you do want to change that you either have to modify your Action Index to redirect to the action you want in controller or change the default routes.
Aside from the default route, if you always want to launch from a specific page when debugging, you can set the "Start Action" of your web app by right clicking on the project, go to Properties -> Web -> Start Action, check the "Specific Page" radio button, and input the URL you wish to land on.
This can be helpful if you're working on a particular feature in a large web application, and you want to save yourself a few clicks every time you go to debug.
MSDN for reference : Change the Start Action for Application Debugging

Redirecting url to index.aspx page using standard asp.net3.5 and web.config

I have a subdomain that is http://trade.businessbazaar.in . I am dynamically creating urls from database something in this manner http://trade.businessbazaar.in/mycompany. To display details, I have an index.aspx file there,thinking that on every request the index.aspx page will load and display data accodingly. Also, There is a masterpage on the index.aspx page from where i am capturing the text mycompany and query it in database to fetch result. But nothing seems to work.
A genuine link is http://trade.businessbazaar.in/Symparlife. But its unable to load index.aspx. I need a clean approach without any third party dll or rewriters. Directly to push some lines in config and start working. That is url will be the same but index page will get loaded...
In short, i want to say
I need the StackOverflow type clean url mechanism to fetch pages
Thanks in Advance
You can handle the Begin_Request event in Global.asax and add custom code to redirect to index.aspx and convert the parts of the URL into query string arguments. You should use Server.Transfer to keep the URL in the browser.
I'd recommend upgrading to 4.0 and using the Routing enine though. You should check if the standard routing is available as a download for ASP.NET 3.5. I am sure your code will get messy very soon. Been there, done that.
As #Mike Miller mentions in the comments the Routing engine ships with ASP.NET 3.5. You can check the documentation here - http://msdn.microsoft.com/en-us/library/system.web.routing(v=vs.90).aspx
Here is a tutorial on how to use it with Web Forms - http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx
For your case the code would be something like:
routes.MapPageRoute("company-index", "/{company}", "~/index.aspx")
And in index.aspx you can access the route value for company like this:
string company = (string)Page.RouteData.Values["company"];
Keep in mind that you'd better add something in the URL before your actual argument (the company name). If you don't you will have problems later on when because you may want to add a URL like "/Login" but then you will have to validate that users can't create a company named "Login". Not how Stack Overflow has "/questions/" before the actual question info in the URL.

Remapping a URL to a MVC application

I'm remaking a website, previous build on DotNetNuke. I need to keep the database, as old URLs working.
The issue: translate the old URL
eq.
http://localhost:8069/Noticias/tabid/78/language/pt-BR/nid/2267/Palestra-
discute-o-futuro-profissional-das-crianca.aspx
to the new mapping engine, that would be something like that:
eq.
http://localhost:8069/{controller}/{action}/{id}/{title}
where, in the example, 2267 is my id, and 78 is the module id that i have to 'translate' for a controller name. The action is view by default.
Any suggestions?
Simply make a base page handler for the requests you want to transfer, and then do a simple Response.Redirect to the appropriate URL on your new website then. All your pages inherit these changes, and you can provide a listing of URLs in a configuration file or database for the URLs to dynamically redirect.

Getting text after URL in asp.net / URL Rewriting (sort of!)

My app is a very simple "one page" type app-
It has Default.aspx
I'm basically trying to get, for example:
www.myappurl.com/this is my text
I want to get hold of "this is my text" from the above example.
This will be displayed on the page (for now)
I didn't really want to have to use any complext url rewriting things for this...
(My hosting provider uses IIS6)
I tried using a 404 handler, but this is a bit long winded, and i'm using shared hosting, that can't set the "execute url" on custom 404 pages.
Any other ideas?
You can add a mapping for all requests with the * extension to the ASP.NET isapi dll (GET/POST) verbs. You will need to uncheck the "verify file is on disk" checkbox when mapping the extension in IIS. (In IIS7 integrated mode, you map the extension in the web.config as well). Note that this will caause everything to be served by asp.net, even images and script files, which can slow things down.
Then create a handler mapping in your web.config to a http handler you create.
From there, in the ProcessRequest() method of the handler, you have access to the HttpContext that spawned the request and can manipulate the URL from there.
That is the easiest option, you could also create a HttpModule, or have the default page at root redirect to http://www.domain.com/default.aspx/this is my text, in the code-behind of default.aspx, you will be able to get the text following the page and slash.

Categories

Resources