web.config file not there in the root(/) directory - asp.net

I was trying to run a .cshtml file but it gave an error:
Server Error in '/' Application.
--------------------------------------------------------------------------------
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /index.cshtml
So I searched for the solution and found that I had to edit the web.config file which is in the root directory(here it is My Site), but there is no file like that there there is only an index.cshtml which I had created.
I searched even the IIS and the IIS Express folders in Programs Files\ but there was no file like that?

If you are using WebMatrix, maybe your mistake was the starting point choice.
If you want to create a new Web Pages site you must start from a template in the Template Gallery of WebMatrix. Pay attention that the Empty Site template differs from the Empty Site option outside the Template Gallery because the first holds the files (binaries, packages and the web.config too) that are needed.

As the server error suggests, .cshtml files are not served, the reason for this is because they are server-side files that make up your application, they are just one piece of a much bigger picture.
If you launched your web application in debug mode and the URL in the browser was something like http://localhost:2932/Views/Home/Index.cshtml, just drop the /Views/Home/Index.cshtml part of the URL.

Related

Is default.aspx a .Net equivalent to an "index" file?

I have just started to work for a new company as a web developer, previous research has led me to find out their site is built in asp.net which isn't a problem, I just dont have any experience in this, all my experience is html, css, php and Js.
Upon gaining access via ftp, I noticed there is no traditional index.bla, so I went to the homepage on their website, and in stead of index, it was default.aspx.
Is this "default.aspx" file the .Net replacement / equivalent of an index file, and does it work in the same way?
Yes. In IIS (the web server) you can specify which files will be shown when a directory (like the root, when accessed through http://www.sitename.tld/) is requested.
You can configure which files will be shown and in what order. Like here (IIS 6):
So when a user requests a directory on that site, IIS will search for "Default.htm", if that isn't found it'll look for "Default.asp" and so on. If none of the default documents are found, you will either see the directory's contents (disabled by default) or an error saying you can't see the directory's contents.
In Apache this is set through the DirectoryIndex directive in httpd.conf.
Yes. index is an arbitrary name that Apache defaults to. The index page can be named anything, and with IIS it is usually default.

running asp.net solution containing multiple projects in iis

I have an asp.net solution containing more than 1 projects which are inter-related and each project have different configurations in web.config file. The whole solution is kept in a folder, lets say 'X'. I want to run the solution in iis. For that, I have created a virtual path in iis of 'X', converted the folder 'X' to an application, and created a web.config file in the root folder that is 'X'.
When I am viewing one of the project' default page in browser, it shows an error of
Parser Error Message: Could not load type 'app1.SiteMaster'
I have already compiled the solution.
Please help... Am i missing some settings...
It sounds like the application can't find the master page. Assuming that your projects share the same master page, you probably need to update the path to the master page to the relative path from the root.

Download existing file from IIS results in File does not exists (404)

I have a full working web site that i ported to a new hosting company.
In some pages i have links to PDF on the server (they do exist!)
On the old server no problem.
On the new one when user clicks on the link : error 404 file does not exist...
Should i look in the web.config ? i don't know where to start
thanks
John
Start from the file read permissions.
You need to read the log files, or the event viewer to see whats really is the problem.
This is probably as simple as the files not being in the exact relative location to the page that they used to be in - e.g. there was a folder /pdfs in the root of the web where all the files were, now they are just in the root folder, and the links were not updated.
You've not said which version of IIS you're using. However for IIS5, this has been answered over at ServerFault -- see https://serverfault.com/questions/79094/serve-pdf-fies-in-iis
It should be similar for IIS6. It's possible your hosting provider may have revoked the MIME type so IIS no longer recognises it.
What you may end up needing to do if your hosting company isn't forthcoming is write a "file provider" page that takes the file to download on the query string (obviously with some sanity checking so folk can't request any old file), then just writes it out, bypassing what IIS would do normally.

Custom VirtualPathProvider unable to serve URLs ending with a directory

As part of a CMS, I have created a custom VirtualPathProvider which is designed to serve a single file in place of an actual file structure. I have it set up such that if a file actually exists on the server, that file will be served. If the file does not exist, the virtual content stored for that address will be served instead. This is similar to the concept of serving a website from files stored in a database, though in this case the content is stored in XML files on the server.
This setup works perfectly when a request is made to a specific page. For example, if I ask for "www.mysite.com/foobar.aspx", the content that is stored for "foobar.aspx" will be served. Further, if I ask for "www.mysite.com/subdir/foobar.aspx", the appropriate content will also be served.
The problem is this: If I ask for something like "www.mysite.com/foobar", things begin to fall apart. If the directory exists on disk (and doesn't have a configured default page in IIS, such as index.aspx), I will get a "Directory Listing Denied" error. If the directory does not exist, I'll simply get a 404 - Resource Not Found.
I've tried several things, and so far nothing I've done has made a bit of difference. It seems as though IIS is simply noting the nonexistence of a directory (or default file in an existing directory) and serving up its own error code, without ever asking my application what to do with the request. If it ever did get to the application, I would be able to solve the problem, but as it stands, I'm quite lost. Does anyone know if there is some setting in IIS that is causing this?
I've looked for every resource I can find on the subject, and am coming up empty. I know this should be possible, because I have read tutorials on serving content from both databases and ZIP files. HELP!
p.s., I am running IIS6 and .NET 3.5
IIS will only pass a request to the ASP.NET process if it is configured to do so for the particular extension. The default is aspx, ascx, etc. In other words, if you request a .html file, ASP.NET will never see that HTTP request. Likewise for empty extension.
To change this behavior, add a wildcard mapping to the ASP.NET process. Load IIS Manager, go to the Properties for your web site and look at the Home Directory tab. Click on "Configuration" and there you will see the extension-to-applicaiton mappings.

Web Service fails when referencing it in another site in IIS

I've got a C# 3.5 web service that works fine when its accessed at http://domain/foo/bar/WS.asmx
The /foo/bar part could change in the future so I want to give people a more stable URL that I could update without requiring any changes from them. I created a site in IIS and set it's Home Directory to where WS.asmx is. Now when I try to access it from http://domain2/WS.asmx, I get:
Description: An error occurred during
the parsing of a resource required to
service this request. Please review
the following specific parse error
details and modify your source file
appropriately.
Parser Error Message: Could not create
type 'Namespace.WS'.
Source Error: Line 1: <%# WebService
Language="C#" CodeBehind="WS.asmx.cs"
Class="Namespace.WS" %>
The assemblies in both cases are at http://domain/bin but when I come from domain2 it doesn't seem to know where to find the \bin that is 3 folders up in the file system.
The namespace/classes are more descriptive than that, I just made them basic for the purposes of this question.
Sorry, AFAIK you can't pull DLLs from explicit file paths outside the root of your website. You generally have two choices:
1) use the /bin directory of the current app (make a copy of the other app's /bin)
2) put the DLL into the Global Assembly Cache (GAC)
BTW, this has been asked in a few other spots on SO, like here.
One thing you could do, if your /bin DLLs are only used inside /foo/bar/, is to convert into an IIS application, and then move the DLLs into a new /foo/bar/bin directory. Then you'd only have one copy of the DLL's to manage.

Resources