ASP.NET MVC application root changes on submit - asp.net

I've got a simple ASP.NET MVC application for CSV file validation. The user enters some characteristics about the file (text box and some checkboxes), then browses to the file they want to upload and hits submit. The entire application works fine on my local machine and also on an internal web server, but does not work when placed in the external hosting environment. Below are the details.
Originally the file contents on my machine were copied out to the server. This means that bundling of the CSS and JS was not enabled. The application page would render just fine and the submit would also work. However, after submitting the file, the application root changes.
I've been checking the application root with the following code places inside the view.
var applicationpath = '#Url.Content("~/")';
The path is correctly output as something like the following when it's rendered for the first time.
var applicationpath = '/folder1/folder2/folder3/appfolder/';
After submitting the file, it changes to.
var applicationpath = '/folder1/folder2/folder3/';
I've checked with the hosting provider and they've got the application set up on "appfolder" and "folder3" is just a directory in IIS and not set up as an application.
The form in the MVC view is set up to post in the following way.
#using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = "multipart/form-data", id = "wizard" }))
Since the path changes, this obviously messes up any #Url.Action,#Html.ActionLink, and other Razor methods that are supposed to automatically map to the root. The odd thing is that the CSS and JS files continue to be mapped in the rendered output.
After all of that, I decided to try to Publish the application through Visual Studio to a local file folder and then copy the results out to the hosting provider. This enabled bundling for the CSS and JS files. Now when I go to the root of the application, none of the CSS or JS is pulled down. I've tried grabbing the path to the bundled JS or CSS files and putting that in the browser, but I get a 404 error. The rendered output looks like this:
<link href="/folder1/folder2/folder3/appfolder/Content/css?v=J7SZFaeCsOxTbb847HlSpnWlcb1lMDolldSj5wq-hdc1" rel="stylesheet"/>
Needless to say, I'm at a loss. I've asked the hosting provider to tell me what IIS features they have installed and they have. See below.
IIS Features 1
IIS Features 2

The 3rd party was able to give me RDP access to the server. I turns out that they were using URL Rewrite in IIS and some of the rules were interfering with the MVC application. After they disabled the rules for the application folder, everything worked as it should.

Related

How to create a hyperlink a new ASP.NET web form in a Webapplication

I am trying to add a new web form to an ASP.NET web application. However, wen I add a hyperlink to it from my main page, I get an IIS error. I am running it on localhost, i.e. my own machine without a web server. The hyperlink is:
Products
I have a products folder and a products.aspx file in it.
My Solution Explorer window:
This is the IIS error I get:
The "~/Products" points to a directory rather to a file, thus your IIS complains that it is not allowed to show the contents of the directory.
Point to the file instead
Products
You need to add runat="server" as well to resolve the dynamic starting location.
Products
This is needed so that ASP.NET CLR engine can dynamically update the path prior to delivering the final HTML code.
I read that you moved Products.aspx page to the root of your site, but you're not able to display the page.
Try replacing the existing code with this. And make sure runat="server" is included.
<a runat="server" href = "~/Products">Products</a>

ASP domain and files

I have no idea about asp, but I had to do some modifications in a web site, an easy modification. So I downloaded all files from server and I did all the modifications in Visual Studio 2013. Then I tested each page in the local host and it was perfect.
When I uploaded the files, I created a folder called "development", to tested it before I changed in the real site, so, my real site is for example "www.realsite.com" and my new folder is inside, with all the file, so I write in my url "www.realsite.com/development" and it shows the page, but not the one I had modified, but the real site. I want to know if there is a config file to change the path of the development site to see the changes I make and not the real site, because if I click in the development site a menu, it sends me to the page in the real site.
I hope you can help me with this,
Thank you!
PS: Do you know what is the meaning of "~/" in for example : src="~/folder/folder/xxxx.xx"
This is because the URLs in the project are using absolute paths, all pointing to the root. If they were using relative paths, moving the project to a folder and running it from there would work just file.
The difference:
... <-- absolute, note the leading slash
... <-- relative, no leading slash
Well, it depends on what kind of changes you are referring to, what kind of ASP.net site (or application).
The ~/ in ASP.Net means "path from application root". A subfolder (the new folder you created) in an existing application is just that, a folder. It is not "another application root". So if the existing code refers to "its root", e.g. where it uses ~/, it's probably not what you would expect..
Again, not enough info, but if you experience more unexpected behavior, it will probably be because of this (application scope).
Ref: ASP.NET Web Project Paths
ASP.NET includes the Web application root operator (~), which you can use when specifying a path in server controls. ASP.NET resolves the ~ operator to the root of the current application.
Hth...

Updating .aspx pages

I've inherited an ASP.NET project that uses a single Default.aspx file in the public_html root to do most of the work.
The changes I'm making are minor, but I can't seem to get them to stick. If I edit the Default.aspx file, the server will still serve the old version. Creating a new .aspx file will initially compile it and run it, but then it's stuck in its "original request" form.
I thought .aspx files were subject to "dynamic recompilation" if they were changed, but this isn't triggered in my case. I've tried updating the Web.config file but is has no effect.
I'm not using Visual Studio for this, yet. I'd like to be able to just edit and update the files, if possible (the changes are very minor and I don't have ready access to a Windows machine). The only access I have to the server is through FTP.
Seems the issue was with my host, who aggressively cache stuff. I have to do a "restart" from inside their control panel to have the changes reflected.
The host is Loopia.se, in case anyone else is using them. Use "Omstart av ASP.NET-applikationer" from inside the Customer Zone to restart things.
(Yes, I do feel kind of silly now)
If the site has previously been 'published' in visual studio as pre-compiled and not-updatable, then changing the aspx files will result in no change:
http://msdn.microsoft.com/en-us/library/1y1404zt(v=vs.80).aspx
In this case everything will have been pre-compiled into DLL's, and the aspx pages are just there as hooks for the .net runtime.

How do I download an msi file via an asp.net button?

So, I've created my wonderful winforms app that I want to unleash upon the world, and now I am trying to create a simple website to host some basic information and link to the setup file (msi installer file )....
I have a button on the asp.net page and the setup file setupApp.msi in same folder as the asp.net page. I am currently trying the following:
Response.Redirect("http://./SetupApp.msi");
But this best guess at what to do is not working. Is there something wrong with Mime types here? What do I need to put in the click event to allow users to download this file?
The path you are passing in to the method is not valid (there's no server name called ".").
You can pass in a relative path and it should work fine because ASP.NET will resolve the path:
Response.Redirect("SetupApp.msi")
Or if it's not in the same folder, try one of these:
Response.Redirect("../Downloads/SetupApp.msi")
Response.Redirect("~/SomeFolder/SetupApp.msi")
Keep in mind that you don't necessarily have to do the whole redirect at all. Instead of writing code in an ASPX file you could just have a link to your MSI:
Download my app!

Is there a way to get rid of aspx placeholder files in a ASP.NET web deployment project?

I'm using a web deployment project in order to precompile my ASP.NET 3.5 web project. It creates a single extra DLL for the code in aspx and ascx files. And, for every aspx file there is a placeholder aspx file (empty) which needs to be copied to the server.
I'd like to simplify the deployment process. Is there a way (configuring the IIS site and adding some sort of http handlers etc.) to get rid of these aspx placeholders?
Also, I'd like to know if there is a way to get rid of the .compiled files in the bin folder. It would make the deployment process smoother.
Thanks!
I discovered it by myself. It is much easier than I thought (IIS 6.0):
In Internet Information Manager go to the property page of the site, then chose the tab "Home Directory" and click on the button "Configuration...".
Click "Edit..." for the .aspx ISAPI extension and uncheck "Verify that file exists". At this point, no aspx file is needed anymore.
Update
One important thing: I had to create an empty "default.aspx" file in the root of the application in order to allow the default document for requests like "http://www.example.com/" (without calling an aspx).
Update 2
Another very important thing: if you're using ASP.NET Ajax PageMethods, then you have to keep the aspx placeholder of that page. If you're omitting the file, a javascript 'PageMethods is undefined' error will be thrown on the browser.
IF it is possible, then it will require, at the least, the mapping in IIS of all possible requests to the asp.net engine. Not very difficult. Then, a HttpHandler should be possible to intercept all incoming requests. That handler should then be able to dynamically load compiled page classes and render them. You'd basically have a single engine DLL that serves page content.
But as you might have noticed from all the should's, it's not a simple thing to accomplish, and I doubt that it's really worth the trouble. What exactly is wrong with these placeholder files being present?

Resources