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
Related
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.
I am working on project wherein there are 8 to 10 different types of project in a solution.
On sharepoint site there is one link say "open dashboard" ,when this link is clicked it navigates to the project I am working on.
Now the problem is when user click this link and a login page which is common for all the 8 to 10 project appears and depending upon selection from drop-down it navigates to that particular dashboard.
Error occurs if user does the following steps :
open two tabs in IE. Navigate using sharepoint site and select the open dashboard and login to Project1. if user repeat the same steps in the second tab, the error occurs(object reference not found).
I have created logs for this however I am not able to dig where the problem as it routes Project2(as an example) which is set default in route table but user has login to Project1 in tab1
what I want to achieve is that user should see same content in second tab as in first tab.
I have done tried so many things but they all are failing..Please correct me where I am going wrong?
I have a little problem with my Redirect in ASP.NET (C#)
I just got a domain which looks like this: http://www.example.com/subdirectory
So when I open my asp.net start page, the url looks like this: http://www.example.com/subdirectory/Startpage/Startpage.aspx
That's my Redirect in code behind:
Response.Redirect("~/UserSite/UserSite.aspx")
The problem now is, when I click on that button, I get redirected to
http://www.example.com/UserSite/UserSite.aspx
instead of
http://www.example.com/subdirectory/UserSite/UserSite.aspx
How can I get my web page to notice the subdirectory in the url?
Would be nice if someone could help me.
Thanks.
This may be because your website under the sub-drecitory hasn't been setup as it's own application within IIS7.
You can do this by:
Open IIS Manager
Open up the website and right click on the sub directory
Click on "Convert to Application"
You can then change the Application Pool if you wish to have a dedicated one or otherwise just click OK.
Response.Redirect("~/UserSite/UserSite.aspx") should then understand that /subdirectory/ is the default website directory
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.
I am working on a site which is programmed in C# .net. It uses a CMS called ADX Studio (a decision which predates my time there) which provides a shonky form of URL Rewriting (as far as I can tell it works by assigning an aspx page as the default 404 handler in IIS).
I have an web form which lives at a rewritten URL. I edited it so that the html form's action points back to the rewritten URL:
var u = new Uri(Request.RawUrl.Split(new char[1] { ';' }).Last());
userAdminForm.Action = u.PathAndQuery;
(kind of ugly but works based on what Request.RawUrl is on these rewritten URLs).
The "pretty" URL is something like this:
http://www.site.com/admin/user/edit/
On my development box (Windows XP/ IIS 5) when I initially tried POSTing back to URLs like this I got a HTTP 405 error. I worked around this by adding a script mapping so Aspnet_isapi.dll handles all (*) requests. And everything works fine on my development machine.
I just pushed my changes to the live server (Windows Server 2003 R2 and IIS 6) and the post fails silently. The page refreshes but all of my logic (from within an IsPostBack path in the code) doesn't get hit. No errors are displayed, it just doesn't work.
If I remove my code setting the .Action of the form then the postback works but it is posting to the ugly URL corresponding to the physical location of the aspx file rather than my page.
Am I missing a simple way to make this work? I don't want to be switching URL rewriting method or anything as this is a large legacy site and is unfortunately pretty dependent on ADX Studio so I don't want to do anything that will break that.
[edited because somehow the code above lost its code highlighting]
The issue is that the page's <form> tag is referencing the "ugly" url as the action. You can resolve that by completely removing the action tag from the form. Browsers will, by default, postback to the same page, ie. the "pretty" url.
This article explains how to accomplish an "actionless" form (~ two thirds of the way down) http://msdn.microsoft.com/en-us/library/ms972974.aspx
It seems like the problem is the same as it was on IIS 5. I can get it to work by doing the following in the IIS Manager:
Right click on the relevant website and select "Properties"
Choose the "Home Directory" tab
Click "Configuration" down in the "Application settings"
Click "Insert" next to the "Wildcard application maps"
Browse to the location of aspnet_isapi.dll (in my case: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll )
Untick "Check that file exists"
Click "OK" back through the Russian doll of dialogs.
This is basically the same as the approach that I linked to in the question for IIS5. However, it's not optimal because IIS is running every request through asp (even static files). Which seems like it can only slow things down. I'd like to be able to specify that asp only needs invoking for HTTP POST requests at least.
The weird thing is that IIS5 gave a HTTP 405 error when POSTing to an extension without a registered ISAPI extension but IIS6 just fails silently. And the page is being run through IIS (I can debug with a breakpoint in the Page_Load function) but IsPostBack (and IsCrossPagePostBack) don't get correctly set. Could it be related to the view state? Is there any alternative to my solution described above?
I've come to what I think is an optimal solution for this problem. It turns out that ADXStudio CMS does use the default 404 rule to do some form of URL rewriting. This has a problem with http POST:
when IIS initially executes a custom
URL on a 404 error, it changes POST to
GET, even if the client does a POST
request.
(thanks to elite brains' blog post about setting up IIS6 and ASP.NET MVC).
Rather than creating my own HttpModule I decided instead to use Ionics Isapi Rewrite Filter to rewrite my URLs. I then set the 404 error handler in IIS to the default. And I created this IIRF.ini file to redirect all requests to the same format as the 404 handler produced:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /Default.aspx?404;http://%{HTTP_HOST}$1 [U,L]
And everything seems to work great. The advantage over my previous answer is that the rewrite code is low level and runs fast and the -f and -d switches mean that if a file actually exists it isn't re-written and so static files don't have the overhead of running through .net.